PDA

View Full Version : Do not explode the dimensions!



fuccaro
19th Nov 2003, 03:21 pm
Sometime I have to work on drawings created by my colleagues. I hate working with exploded dimensions, so I wrote a short Lisp routine and I placed a copy of it on every computer in our office. The routines are in the startup suit so are loaded at startup. I am the only one around here working with Lisp, so I suppose that my routine will remain on place for long time from now. If some of you wish to try, here is the code:
(command "undefine" "explode")
(defun c:explode()
(setvar "cmdecho" 0)
(command "undo" "begin")
(setq q (ssget)
i 0
dim nil
message (strcat " You are going to explode one or more dimension(s)!"
"\nYou exploded until now more than 100 dimension entyes."
"\nPress F1 for help and read about dimensioning in AutoCAD")
)
(repeat (sslength q)
(setq ed (entget (ssname q i))
i (1+ i)
dim (= "DIMENSION" (cdr (assoc 0 ed))))
)
(if dim (alert message))
(command "._explode" q)
(command "undo" "end")
(princ)
)
Probable in the next step I will add the hatches to the “protected list”. Did you ewer try to edit an exploded dot hatch? -I did!

Mr T
20th Nov 2003, 12:38 pm
I see you have non associated the dimensions ?

Flores
18th Dec 2003, 08:25 pm
Here is another routine to prevent dimensions from being exploded, but also adds mtext and blocks to the list. It is really easy to add an entity to be "filtered" whenever you select an object to explode.

;; Created by: Lee Ambrosius
;; Date created : 12/05/03
;; Error Handler added : 12/09/03
;; Corrected looping issue : 12/10/03

;; Filter out Blocks (Inserts), Mtext and Dimensions from the
;; Explode command.

;; Load COM Library for Visual LISP
(vl-load-com)

;; Remove standard Explode Command
;; Standard Explode can still be accessed via the . (period) in front of the command name

;; Save current value of CMDECHO into a local variable
(defun undefine-cmd ( / SAV-CMDECHO)
(setq SAV-CMDECHO (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(command ".undefine" "explode")
(if (/= SAV-CMDECHO nil)
(setvar "CMDECHO" SAV-CMDECHO)
)
(princ)
)

(undefine-cmd)

;; Custom Explode Command Override
(defun c:explode ( / SS SS-FILTER SAV-CMDECHO SAV-NOMUTT SS-CNT CNT-LOOP
UNDOFLAG EXPLODE-ERROR OLDERR)

;; Save current value of CMDECHO into a local variable
(setq SAV-CMDECHO (getvar "CMDECHO"))
;; Save current value of CMDECHO into a local variable
;; Check for AutuCAD version and if 2000 - 2004 then run additional code
&#40;if &#40;< &#40;atoi &#40;substr &#40;getvar "ACADVER"&#41; 1 2&#41;&#41; 15&#41;
&#40;setq SAV-NOMUTT &#40;getvar "NOMUTT"&#41;&#41;
&#41;

;; Custom error handler
&#40;defun EXPLODE-ERROR &#40;S&#41;
&#40;if &#40;/= S "\nFunction cancelled"&#41;
&#40;princ "\n"&#41;
&#41;
&#40;if &#40;= UNDOFLAG T&#41;
&#40;progn
&#40;command "._undo" "end"&#41;
&#40;command ".u"&#41;
&#41;
&#41;
&#40;if &#40;/= SAV-CMDECHO nil&#41;&#40;setvar "CMDECHO" SAV-CMDECHO&#41;&#41;

&#40;if &#40;< &#40;atoi &#40;substr &#40;getvar "ACADVER"&#41; 1 2&#41;&#41; 15&#41;
&#40;if &#40;/= SAV-NOMUTT nil&#41;&#40;setvar "NOMUTT" SAV-NOMUTT&#41;&#41;
&#41;
&#40;setq *ERROR* OLDERR&#41;
&#40;princ&#41;
&#41;

&#40;setq OLDERR *ERROR*
*ERROR* EXPLODE-ERROR
&#41;

;; Build entity exclusion filter
;; Use the expression to find out the DXF 0 value that needs
;; to be placed in the filter. &#40;entget &#40;car &#40;entsel&#41;&#41;&#41;
&#40;setq SS-FILTER
&#40;list
&#40;cons -4 "<NOT"&#41;
&#40;cons -4 "<OR"&#41;
&#40;cons 0 "INSERT"&#41;
&#40;cons 0 "MTEXT"&#41;
&#40;cons 0 "DIMENSION"&#41;

;; By filtering out Lines, Circles and Arcs it helps to reduce unnecessary prompts
;; at the command line
&#40;cons 0 "LINE"&#41;
&#40;cons 0 "CIRCLE"&#41;
&#40;cons 0 "ARC"&#41;
&#40;cons 0 "TEXT"&#41;
&#40;cons 0 "SOLID"&#41;
&#40;cons -4 "OR>"&#41;
&#40;cons -4 "NOT>"&#41;
&#41;
&#41;

;; Ask the user to select some objects with our filter in place
&#40;setq SS &#40;ssget SS-FILTER&#41;&#41;

;; Check to see if Selection Set is empty
&#40;if &#40;/= SS nil&#41;
&#40;progn
;; Change current value of CMDECHO to 0, then no additional prompts will be displayed
&#40;setvar "CMDECHO" 0&#41;

;; Start our undo stack call
&#40;command ".undo" "begin"&#41;

&#40;if &#40;< &#40;atoi &#40;substr &#40;getvar "ACADVER"&#41; 1 2&#41;&#41; 15&#41;
&#40;setvar "NOMUTT" 1&#41;
&#41;

&#40;setq UNDOFLAG T&#41;

;; Set up counters
&#40;setq SS-CNT &#40;sslength SS&#41;
CNT-LOOP 0
&#41;

;; Loop through all objects in the Selection Set
&#40;while &#40;< CNT-LOOP SS-CNT&#41;
;; Explode the object
&#40;command ".explode" &#40;ssname SS CNT-LOOP&#41;&#41;

&#40;if &#40;= 1 &#40;boole 1 &#40;getvar "cmdactive"&#41; 1 &#41;&#41;
&#40;command ""&#41;
&#41;

;; Add one to the counter
&#40;setq CNT-LOOP &#40;1+ CNT-LOOP&#41;&#41;
&#41;

;; Restore original value to th variable NOMUTT
&#40;if &#40;< &#40;atoi &#40;substr &#40;getvar "ACADVER"&#41; 1 2&#41;&#41; 15&#41;
&#40;setvar "NOMUTT" SAV-NOMUTT&#41;
&#41;

;; End out undo stack call
&#40;command ".undo" "end"&#41;

;; Restore original value to th variable CMDECHO
&#40;setvar "CMDECHO" SAV-CMDECHO&#41;
&#41;
&#40;progn
;; Echo None found like the core Explode command does.
&#40;prompt "\nNone found."&#41;
&#41;
&#41;
&#40;setq *ERROR* OLDERR&#41;
&#40;princ&#41;
&#41;

;; Don't send echoes to screen
&#40;princ&#41;

Flores