乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 68|回复: 19

[编程交流] Auto-Dimension-Update LISP

[复制链接]

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 06:34:21 | 显示全部楼层 |阅读模式
Hi Guys,
 
This LISP works - sort of.
 
It will produce the desired result, but will return an error in doing so, and I can't work out why.
 
The LISP is supposed to grab all dimensions from all the layers in my template and dump them on a "DIM" layer. Also, update the dimstyle of the dimensions to the STANDARD style as set in my template.
 
I would appreciate any help or advice anyone is willing to provide.
 
  1. (defun c:dimupd (/ oldcmd laylist ss1)      (setq oldcmd (getvar "cmdecho"))   (setvar "cmdecho" 0)   (if (not (tblsearch "LAYER" "DIM"))   (command "-layer" "m" "DIM" "C" "2" "DIM" ""))   (command "-dimstyle" "Restore" "Standard")   (setq laylist '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9"                   "BORDER" "Defpoints" "SIGNATURE" "TEXT"))   (foreach lay laylist       (setq ss1 (ssget "X" (list (cons 0 "DIMENSION") (cons 8 lay))))       (command "_chprop" ss1 "" "LA" "DIM" "")       (command "-dimstyle" "Apply" ss1 "")   ) ; end foreach   (setvar "cmdecho" oldcmd)   (princ))
This is the error I receive upon running the LISP:
 
This appears 13 times - i.e. one for each repetition of the foreach command.
回复

使用道具 举报

1

主题

316

帖子

311

银币

初来乍到

Rank: 1

铜币
29
发表于 2022-7-6 06:40:36 | 显示全部楼层
  1. (defun c:dimupd        (/ oldcmd laylist ss1)   (setq oldcmd (getvar "cmdecho"))   (setvar "cmdecho" 0)   (if        (not (tblsearch "layer" "dim"))(command "-layer" "m" "dim" "c" "2" "dim" "")   ) ;_ end_if   (command "-dimstyle" "restore" "standard")   (setq laylist '("0"            "1"            "2"            "3"            "4"            "5"            "6"            "7"            "8"            "9"            "border"            "defpoints"            "signature"            "text"           )   ) ;_ end_setq   (foreach lay laylist(if (setq ss1 (ssget "x" (list (cons 0 "dimension") (cons 8 lay))))    (progn        (command "._change" ss1 "" "p" "layer" "dim" "")        (command "-dimstyle" "apply" ss1 "")    ) ;_ end_progn) ;_ end_if   ) ;_ end_foreach   (setvar "cmdecho" oldcmd)   (princ)) ;_ end_defun
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 06:41:15 | 显示全部楼层
Thanks Wizman,
 
LISP works perfectly - I just added an extra line including storing a variable for the previous current layer, so that when the LISP completed, the user would still remain on the layer he/she was previously working on.
 
But, I can't quite understand why my original LISP did not work - was it the exclusion of the IF function when retrieving the dimensions or was it the use of CHPROP instead of CHANGE?
 
Or was it possibly just a ridiculously stupid typo error?
回复

使用道具 举报

1

主题

316

帖子

311

银币

初来乍到

Rank: 1

铜币
29
发表于 2022-7-6 06:46:13 | 显示全部楼层
i was just not used to using 'chprop' leemac, thats why i use the 'change' command. just tested in your original lisp, only wrap the ss1 in an if function like the one i did in my first post and it will also work. Another one you can also add if you want is to check whether dimension style 'standard' exists in your drawing...
 
 
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 06:49:53 | 显示全部楼层
Ahh, excellent - its good to know that I wasn't far off the mark with my original LISP, thanks for your help Wizman.
 
As for the inclusion of an extra line to check dimstyle existence, would something like the following suffice? :
 
  1. (if (tblsearch "dimstyle" "standard")   (progn    ...   ) ; end progn   (alert "\nStandard Dimstyle Doesn't Exist.")) ; end if
回复

使用道具 举报

1

主题

316

帖子

311

银币

初来乍到

Rank: 1

铜币
29
发表于 2022-7-6 06:51:43 | 显示全部楼层
 
 
exactly, that will test if dimstyle>standard is present, youre on the right track, keep up!
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 06:55:39 | 显示全部楼层
Hi Guys,
 
Just thought I'd post the final version, if it is of any use to anyone:
 
  1. ;|   .: Automatic Dimension Updater :.    .: Function Syntax : DIMUPD :.        .: by Lee McDonnell :.     (With credit to Wizman & ASMI for help and coding).|;(defun GetLayerList ()   (vl-load-com)   (vlax-for l        (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))       (setq oLst (cons (vla-get-Name l) oLst))   ); end vlax-for   (reverse oLst)); end of GetLayerList(defun c:dimupd (/ oldcmd oldlay laylist ss1)   (setq oldcmd (getvar "cmdecho"))   (setq oldlay (getvar "clayer"))   (setvar "cmdecho" 0)   (if (tblsearch "dimstyle" "standard")       (progn           (if    (not (tblsearch "layer" "DIM"))                  (command "-layer" "m" "DIM" "c" "2" "DIM" "")            ) ; end if           (command "-dimstyle" "restore" "standard")           (GetLayerList)           (foreach lay oLst               (if (setq ss1 (ssget "x" (list (cons 0 "dimension") (cons 8 lay))))                   (progn                       (command "._change" ss1 "" "p" "layer" "DIM" "")                       (command "-dimstyle" "apply" ss1 "")                   ) ; end progn               ) ;  end if           ) ; end foreach       ) ; end progn       (alert "\nStandard Dimstyle Does not Exist.")   ) ; end if   (setvar "clayer" oldlay)   (setvar "cmdecho" oldcmd)   (princ)) ; end defun
回复

使用道具 举报

2

主题

8

帖子

6

银币

初来乍到

Rank: 1

铜币
10
发表于 2022-7-6 06:59:10 | 显示全部楼层
How would you add leaders to the code?
I seems to always miss one or two along the way.
 
Bill
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 07:01:58 | 显示全部楼层
Blimey, this is a long time ago - this was one of the first LISP's I wrote
 
Perhaps this:
 

[code](defun c:dimupd (/ *error* ocm lays ss) (defun *error* (msg)   (if ocm (setvar "CMDECHO" ocm))   (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))     (princ (strcat "\n>")))   (princ)) (setq ocm (getvar "CMDECHO")       lays (vla-get-layers              (vla-get-ActiveDocument                (vlax-get-acad-object)))) (setvar "CMDECHO" 0) (or (tblsearch "LAYER" "DIM")     (vla-put-color       (vla-add lays "DIM") 2)) (if (and (tblsearch "DIMSTYLE" "Standard")          (setq ss (ssget "_X" '((0 . "LEADER,DIMENSION")))))   (progn     (command "-dimstyle" "_R" "standard")     (command "_.chprop" ss "" "_LA" "DIM" "")     (command "-dimstyle" "_A" ss ""))   (princ "\n
回复

使用道具 举报

1

主题

6

帖子

5

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-6 07:02:58 | 显示全部楼层
Hi Lee
 
just tried the block update and i works, but it looks like the code makes the "dim" layer, what would be the change to have it set the layer properties if the layer "dim" exists.
 
we are updateing older dwg's and they already may have the right "dim name" but we are wanting to change the dim properties
 
Glen
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-10 18:46 , Processed in 0.420790 second(s), 72 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表