AutoLISP will not completely undo

AutoLISP will not completely undo

Anonymous
Not applicable
889 Views
3 Replies
Message 1 of 4

AutoLISP will not completely undo

Anonymous
Not applicable

I posted earlier and got an answer to my question about changing layer colors with one command.

This is what I've come up with to change the colors of some of the layers:

 

(defun c:LayCol ()

(command "_.layer" "_color" 8 "*" "")
(command "_.layer" "_color" 5 "E-CKT" "")
(command "_.layer" "_color" 2 "E-RECEPTACLES" "")
(command "_.layer" "_color" 1 "E-CKT-NO" "")
(command "_.layer" "_color" 4 "B-TEXT" "")
(command "_.layer" "_color" 2 "E-LITE-NEW" "")

) ;end function
(princ)

 

However, I have to hit the undo button multiple times to undo the layer color changes. How can I condense this into one command that will completely undo with one click of the 'undo' button?

I'd like to keep the code as simple as possible, so someone else could come in and add layers as needed.

 

Thanks

0 Likes
890 Views
3 Replies
Replies (3)
Message 2 of 4

ВeekeeCZ
Consultant
Consultant

Don't finish the layer command until you're done.

 

(defun c:LayCol ()

(command "_.layer"
	 "_color" 8 "*"
	 "_color" 5 "E-CKT"
	 "_color" 2 "E-RECEPTACLES"
	 "_color" 1 "E-CKT-NO"
	 "_color" 4 "B-TEXT"
	 "_color" 2 "E-LITE-NEW"
	 "")

) ;end function
(princ)

 It makes just one LAYERP record. It also may solve your issue....  

Message 3 of 4

scot-65
Advisor
Advisor
In addition to BeekeeCZ's eloquent answer, there may be
a time when there are more than one command in a utility.

For multiple commands in a utility, one can use this:
(defun c:ABC ( / a b c *DOC* )
(vl-load-com)
(vla-StartUndoMark (setq *DOC* (vla-get-ActiveDocument (vlax-get-acad-object))))

;utility body goes here

(vla-EndUndoMark *DOC*)
(princ)
);end c:ABC

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 4 of 4

doaiena
Collaborator
Collaborator

For a beginner, i would suggest:

(defun c:ABC ( / a b c )
(command "_.undo" "_begin")

;utility body goes here

(command "_.undo" "_end")
(princ)
);end c:ABC

Visual Lisp looks scary to a beginner, especially if they are new at programming. A more "script-like" look to the code seems more natural and easier to read. When/If he feels the need to progress further, im sure he will find the more advanced options.