[Search tip detail and code files using keywords, tip number, author name, etc ]
 
Unlock a Layer and Make it Current
Tip# 3928 By Dave Alexander On 02-Jul-2012
0
Rated By 0 users
Categories : Layer Tools
Software type : AutoCAD 2013
Rename File To : No Files to download.
This macro unlocks the layer G-ANNO-REFR.

Tipster Dave Alexander shares a macro with us that will unlock a specific layer in AutoCAD and make it current.

"Efficiency with AutoCAD can be increased by reducing the number of mouse button clicks. Using tool button toggles to change from one layer to another layer and then back again is fun and efficient. Everyone has a specific layer for attaching xrefs. For instance, G-ANNO-REFR; this layer is usually locked. To manage your xrefs you have to make the G-ANNO-REFR layer current and unlock it. Now you can do what you need to do with the xrefs. When you are finished, you have to lock the layer and find your way back to the previous layer. The following is from a tool bar button that I have. You can assign it to a shortcut key, tool palette item, a menu item, or a toolbar button, which is my preference."

^C^C(IF (= (STRCASE (GETVAR "CLAYER")) "G-ANNO-REFR")
(progm (SETQ LA3 LA1)(command "-layer" "LO" "G-ANNO-REFR" "" ))
(progm (SETQ LA1 (GETVAR "CLAYER") LA3 "G-ANNO-REFR")
(command "-layer" "U" "G-ANNO-REFR" "" )));'-layer;M;!LA3;;;

Notes from Cadalyst Tip Reviewer Brian Benton: This macro is really quite simple. It makes the layer G-ANNO-REFR current and unlocks it. It sounds simple enough to do manually, but if you have to do this many times in your workflow it can be very frustrating. Add this bit of code to a tool palette, toolbar, the Quick Access toolbar, etc., and then it’s just a quick flick of the wrist and a click.

 

Average Rating:
0


User comments
Comment by Cooper,Kent
Posted on 2012-07-02 09:05:18
[Correct the spelling of a function" (progM should be (progN instead.] A shorter way to accomplish the same thing: ^C^C(if (= (strcase (getvar 'clayer)) (setq LA1 "G-ANNO-REFR")) (command "_.layer" "_lo" LA1 "_s" LA2 "") (progn (setq LA2 (getvar 'clayer)) (command "_.layer" "_s" LA1 "_u" LA1 "")))
Comment by Cooper,Kent
Posted on 2012-07-02 09:12:31
[Just realized it didn't account for the possibility that the G-ANNO-REFR Layer might not already exist. And just in case it does, but might be frozen:] ^C^C(if (= (strcase (getvar 'clayer)) (setq LA1 "G-ANNO-REFR")) (command "_.layer" "_lo" LA1 "_s" LA2 "") (progn (setq LA2 (getvar 'clayer)) (command "_.layer" "_t" LA1 "_m" LA1 "_u" LA1 "")))
Comment by Cooper,Kent
Posted on 2012-07-02 09:28:38
And one more little comment: all of these routines assume that the only way you get into that G-ANNO-REFR Layer is by using the same routine. If you get into and unlock that Layer manually, without having used the routine to do it previously, the name of the current Layer at the time won't be saved, and all of these will have a problem with nil as a Layer name. That can be avoided by giving it a backup Layer to use if needed, such as [in this case] Layer 0: (if (= (strcase (getvar 'clayer)) (setq LA1 "G-ANNO-REFR")) (command "_.layer" "_lo" LA1 "_s" (cond (LA2) ("0")) "") (progn (setq LA2 (getvar 'clayer)) (command "_.layer" "_m" LA1 "_u" LA1 "")))
Comment by Cooper,Kent
Posted on 2012-07-02 09:33:25
[I wish I could edit a previously-posted comment....] Left out the Thawing: (if (= (strcase (getvar 'clayer)) (setq LA1 "G-ANNO-REFR")) (command "_.layer" "_lo" LA1 "_s" (cond (LA2) ("0")) "") (progn (setq LA2 (getvar 'clayer)) (command "_.layer" "_t" LA1 "_m" LA1 "_u" LA1 "")))
Comment by Alexander,Dave
Posted on 2012-07-10 18:43:46
Thanks for correcting my progn error. The enhancements you list are nice and appreciated. However, the G-ANNO-REFR is always on and thawed when working with a drawing that has xrefs atttached. Dave Alexander