Community
AutoCAD LT Forum
Welcome to Autodesk’s AutoCAD LT Forums. Share your knowledge, ask questions, and explore popular AutoCAD LT topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Replacing LISP with Macros for AutoCAD LT

23 REPLIES 23
SOLVED
Reply
Message 1 of 24
DesCap
8267 Views, 23 Replies

Replacing LISP with Macros for AutoCAD LT

Greetings.  I am new to this forum, and I am in need of some programming assistance. 

I am in the process of moving from ADT 3.3 to AutoCad LT 2013.  I have numerous LISP rotines (created by former colleagues long since gone) driven by key strokes that are important for my productivity.  I have figured out how to customize some LT keyboard commands to replace the LISP rotines, but I have hit a wall on some others, the most important being layer management.  Could someone provide some guidance in how to code a macro to turn on and turn off certain groups of layers?  A small sample of the layers would be:

 

p-dimen

p-doors

p-roomnames

p-stairs

p-text

p-walls

p-windows

 

I have many more layers, but if I can get one example, I think that I can create the rest of them.

It would be great to assign a keystroke(s)  (e.g., "pon" for plan layers on) as I am familiar to this, otherwise, I'd be happy to change my behavior to use a button on a toolbar to toggle the layers on and off.

 

I am not a programmer and could use the help.

Thanks!

 

23 REPLIES 23
Message 2 of 24
hwalker
in reply to: DesCap

Create a Script file. These are simple text files with the extension .SCR

 

Put in the following

 

-Layer OFF p-*

 

or

 

-Layer

OFF

p-*

 

 

NOTE

 

 

At the end of the first suggestion you need to put 2 spaces after p-*as these act as returns

If you use the second suggestion, you need to put 2 hard returns after p-*

 

Howard Walker
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Left Handed and Proud

Message 3 of 24
pendean
in reply to: DesCap

You can't "keystroke" scripts or menu macros, in the AutoCAd shortcut sense of the word that is: just so you know.

The tip above is excellent as a script, it can also be written as a menu macro (Ribbon or Toolbar button, your choice):

 

^C^C_-Layer;OFF;p-*;;

 

A Semi-Colon, better than a blank space, acts like striking <enter> on the keyboard. ^C^C kills any running commands or object selections.

 

Macros are nothing more than an automation of what you can type at the command line in AutoCAD: there is no "lisp" intelligence to it and no keyboard shortcuts to invoke them. Know your commands, especially the commandline versions of the commands you want, and you're prety much 90% there for macro writing.

Message 4 of 24
DesCap
in reply to: DesCap

Thanks to you both for your input.  I'll give this a try and probably assign it a button since I can't use keystrokes to invoke the script.  BTW, I assume that I will need to create two scripts/buttons, one to turn on and one to turn off.  It would be cool if only one button was required and it toggled the layers on and off.  Is this a possibility?

Cheers!  

Message 5 of 24
bgingerich
in reply to: DesCap


@DesCap wrote:

... BTW, I assume that I will need to create two scripts/buttons, one to turn on and one to turn off.  It would be cool if only one button was required and it toggled the layers on and off.  Is this a possibility?


It depends, are you just looking to turn on and off layers?  See sample macro:

^C^Csetenv;layon-off;\$M=$(if,$(=,$(getenv,layon-off),1),turn-layers-on,turn-layers-off)

Put your macros to turn on and off the layers in the appropriate places.

 

 (if ("mysolution"=answer) then (click "Accept As Solution"))
------------------------------------------------------------------------------------

─────────────────────────────────────────────────────────────────────────────────────────────
Brandon Gingerich
Message 6 of 24
DesCap
in reply to: bgingerich

I would be looking to turn on and off certain groups of layers (e.g., floor plan layers as referenced above) with a single button.  Where in your script would you place the "^C^C_-Layer;OFF;p-*;; " script noted above?  Sorry if this is the answer to this question is obvious, but I am out of my comfort zone here.

Message 7 of 24
bgingerich
in reply to: DesCap

Try this:

^C^Csetenv;layon-off;\$M=$(if,$(=,$(getenv,layon-off),1),_-Layer;ON;p-*;;,_-Layer;OFF;p-*;;)

 Type either 0 or 1 at the prompt and it should do the rest for you. 

 

Do you understand the gist of what is going on?  If not I can try to explain what is happening in this macro.

 

(if ("mysolution"=answer) then (click "Accept As Solution"))
------------------------------------------------------------------------------------

─────────────────────────────────────────────────────────────────────────────────────────────
Brandon Gingerich
Message 8 of 24
Charles_Shade
in reply to: bgingerich

Do so please, I think that would be good for anyone who comes across this.

(Of course when you have the time that is. Smiley Wink)

Message 9 of 24
bgingerich
in reply to: Charles_Shade

Are you just too lazy to do it yourself, Charles? Smiley Tongue

 

Anyway, the basics of this macro...  First it creates/modifies an environment variable with a value that the user supplies (should be a 1 or 0).  The fancy '$(' s all over the place are Diesel expressions which can be found in the Help docs; the $M= tells Acad that a menu/Diesel macro is coming up and not to treat it as text for the command line. 

 

$(if,$(=,$(getenv,layon-off),1),...,...)

This is just telling Acad, "If environment var 'layon-off' is found and has a value of 1, do the stuff in between the second and third periods and if it isn't do the stuff in between the third period and the right paren ")". 

 

If "layon-off" equals 1, does the equivalent of typing in this at the command line:

"_-layer" <space/enter> "on" <space/enter> "p-*" <space/enter> <space/enter>

 

Hopefully that makes some sense. Smiley Happy

 

(if ("mysolution"=answer) then (click "Accept As Solution"))
------------------------------------------------------------------------------------

─────────────────────────────────────────────────────────────────────────────────────────────
Brandon Gingerich
Message 10 of 24
Charles_Shade
in reply to: bgingerich

Message 11 of 24
DesCap
in reply to: Charles_Shade

Thanks all for the help.

I have all my layer management LISP routines converted over to LT.  Now on to the others!

Message 12 of 24
Johneng
in reply to: bgingerich

I also had to give you two kudos for those two post. Great solution and follow up explanation.

Message 13 of 24
bgingerich
in reply to: DesCap

This one is even better, a true toggle.  The only thing is that you have to make sure the var "layon-off" (or whatever you're using)  is created/existing with a value of 1 (specifies that said layers are on) before running it. 

^C^C$M=$(if,$(=,$(getenv,layon-off),0),setenv;layon-off;1;_-Layer;ON;m*;;,setenv;layon-off;0;_-Layer;OFF;m*;;)^Z

 HTH!

 

(if ("mysolution"=answer) then (click "Accept As Solution"))
------------------------------------------------------------------------------------

─────────────────────────────────────────────────────────────────────────────────────────────
Brandon Gingerich
Message 14 of 24
pendean
in reply to: bgingerich

There are many on-off needs for AutoCAD users, these tips can be modified with a little imagination to do so much in LT.

I'm sure we all have our favorites, think about it during a typical day of CAD and the flood gates will open.

 

Remember though, SETENV accesses the Windows Registry to add these user "environment variables": some registry cleaners like to remove them. AFAIK limited Windows user accounts are not affected in creating them, but I've never tested it.

Message 15 of 24
dwcreston
in reply to: DesCap

Are there any experts who would be able to create a macro tool that would change all layers in a drawing to one color?

 

Here is something I have started but I am new at this so maybe it would be less steps or some keywords I am not realizing...

 

^C^C_shiftselectalllayers;color;

 

if anyone knows that this would be possible or could tell me if Im wasting my time I would appreciate it!

 

Thanks for the cadvice!

Message 16 of 24
Charles_Shade
in reply to: dwcreston

Welcome to the Autodesk Forums!

 

You can open the Layer Command (LA), Shift select All the Layers as you would any group of files, Click on the Color for one of the layers and change to whatever Color to change all.

 

Can you do this by typing the various Commands at the Command line?

Something like LA, All, Color,...

If so this is what you need to create the Macro

 

 

Message 17 of 24
pendean
in reply to: dwcreston

At the commandline (one for each color you crave):
-LAYER (there is a dash in the name)
COLOR
1 (or whatever color you want)
* (that's a star, shift+8 gets it)
<enter>
<enter>

^C^C-layer;color;1;*;;
Message 18 of 24
dwcreston
in reply to: pendean

Thank you for the input. I see the asterisk has made my macro complete. It's so much easier to do this than opening the layer manager and scrolling down the entire list. Makes the computer work smart instead of waiting for all these windows to pop up which at the end of the day can be strenuous. Making a background all one color is constantly a pain because when the computer is working slow it just seems like a ton of waiting to select anything. Thanks Dean!
Message 19 of 24
dwcreston
in reply to: pendean

Good Evening,

 

quick question at the end of the day. I have spent a half hour reading up on handles and understand each block or attributes have to to be automatically numbered by autocad.

 

My question:

 

is using the same block with the same handles(will not work if the block has different handles) in multiple drawings just fundamentally easier to modify through excel or notepad? Is this a great way to save fonts and text sizing within a block?

 

 

seems that it would be a better tool if the command could take the attributes and applythem to blocks of different shapes and sizes.

 

I just wanna see the broader picture.

 

Thanks for the support in earlier posts!

 

Dan

Message 20 of 24
pendean
in reply to: dwcreston

What is your ultimate goal? LT does not readily give you access to entity handles like full AutoCAD.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost