Coding a Dimension Layer Shortcut

Users share keystroke code to set dimension layers in AutoCAD. September 24, 2006

Question
I used to have a dimension tool button that when pressed would automatically set my dimension layer current. Does anyone know how to create that button again?

Forum Responses
(CAD Forum)
From contributor A:
^C^C_-LA;S;DIMENSIONS;;DIMLINEAR;\\\-LA;S;0;;
The above code will change your current layer to DIMENSIONS, let you run a dim linear command and then change the current layer back to 0. Right mouse click to change the properties of the button. Of course you change the name of the layers in the code to reflect your drawing style.



From contributor B:
Just a couple of rudimentary questions from a toolbar novice here - where do you insert such a code? Does "Dimensions" in the command refer to a particular dimension layer that you use in association with a particular dimstyle?


From contributor C:
^C^C-LA;S;DIM;OFF;H,H1,PL,PL1,PL2,DOTS;;OSNAP;END,INT,MID;-DIMSTYLE;R;DIM4;GRAPHSCR;

This micro turns DIM layer on and makes dimstyle DIM4 current. It also turns certain osnaps off and on. You create new button in acad customize user interface dialog box and associate this micro to that button.



From contributor A:
To contributor B: Yes the "Dimensions" does refer to a layer, but does not refer to a style. You certainly can extend the code to reference a style if you want. Anything is possible.


From the original questioner:
The original code you gave me works great. But, after I place a linear dimension and I right click to restart the command I am getting a bunch of layer options instead of the enter command. My right click is set to enter when nothing is selected. I have tried entering *cancel* to the end of your code to replicate the escape command. That didn’t quite work either. Any ideas?


From contributor D:
Copy this code to notepad and save as cld.lsp in your support folder for AutoCAD.
(defun c:cld ()
;define the function
;**********************************************************
;Start of Command Function
(command "-Layer" "Set" "DIMENSIONS" ""
"Dimlinear" pause pause pause
"-Layer" "Set" "0" ""
) ;End Command
;End of Command Function
;*********************************************************
(princ)
;finish cleanly
) ;end of defun

In AutoCAD, go to Tools->AutoLISP->Load and click on Contents where it says StartUp Suite and the Add. Browse to your AutoCAD support folder and select the cld.lsp file and click Add. Restart AutoCAD once you have clicked Ok. This should load the cld lisp file each time AutoCAD starts. Type in cld. This should start your command. Only using toolbar commands was "stepping through" the commands instead of combining them all into one. There may be a way to do what you want through only toolbars, but I suggest learning AutoLISP, which will make your life a lot easier. There are some good books at Barnes and Noble which cover Lisp programming, and you can also find many helpful online websites. You can also create a toolbar button with the macro ^C^C_cld if you don't feel like typing in cld all of the time - I like using short keyboard entries myself. What industry are you in? Do you do any CNC programming? I am in the countertop industry and do CAD and program our CNC. Maybe we can share some ideas.



From contributor D:
Someone emailed me and asked what the code would be if you wanted to change the layer back to the previous layer instead of Layer 0, so here is the code:
(defun c:cld ()
;define the function
;********************************************************
;Save Current Layer as Variable previouslayer
(setq previouslayer (getvar "clayer"))
;**********************************************************
;Start of Command Function

(command "-Layer" "Set" "DIMENSIONS" ""
"Dimlinear" pause pause pause
"-Layer" "Set" previouslayer ""
) ;End Command
;End of Command Function
;*********************************************************
(princ)
;finish cleanly
) ;end of defun


From contributor A:
Okay so the Autolisps are more powerful. I have never taken the time to learn them but now I will. Can you suggest a book? Like Autolisps for dummies or something? To the original questioner: I do not believe there is a way you can repeat the command. I just hit the button over again.