Auto-Dimension-Update LISP
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.
(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. (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 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? 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...
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? :
(if (tblsearch "dimstyle" "standard") (progn ... ) ; end progn (alert "\nStandard Dimstyle Doesn't Exist.")) ; end if
exactly, that will test if dimstyle>standard is present, youre on the right track, keep up! Hi Guys,
Just thought I'd post the final version, if it is of any use to anyone:
;| .: 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 How would you add leaders to the code?
I seems to always miss one or two along the way.
Bill Blimey, this is a long time ago - this was one of the first LISP's I wrote
Perhaps this:
(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 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
页:
[1]
2