AutoCAD LT General Discussion

AutoCAD LT General Discussion

Reply
Member
DesCap
Posts: 5
Registered: ‎03-21-2010
Message 1 of 24 (3,990 Views)
Accepted Solution

Replacing LISP with Macros for AutoCAD LT

3990 Views, 23 Replies
01-09-2013 03:40 PM

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!

 

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"))
------------------------------------------------------------------------------------

*Expert Elite*
hwalker
Posts: 1,219
Registered: ‎07-14-2004
Message 2 of 24 (3,972 Views)

Re: Replacing LISP with Macros for AutoCAD LT

01-10-2013 02:00 AM 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-*

 

*Expert Elite*
pendean
Posts: 23,304
Registered: ‎11-06-2003
Message 3 of 24 (3,964 Views)

Re: Replacing LISP with Macros for AutoCAD LT

01-10-2013 04:56 AM 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.

Dean Saadallah Blog | Facebook | Google+ | Twitter | PINS
Member
DesCap
Posts: 5
Registered: ‎03-21-2010
Message 4 of 24 (3,949 Views)

Re: Replacing LISP with Macros for AutoCAD LT

01-10-2013 08:48 AM 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!  

Valued Mentor
bgingerich
Posts: 276
Registered: ‎08-29-2011
Message 5 of 24 (3,941 Views)

Re: Replacing LISP with Macros for AutoCAD LT

01-10-2013 10:10 AM 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
Member
DesCap
Posts: 5
Registered: ‎03-21-2010
Message 6 of 24 (3,934 Views)

Re: Replacing LISP with Macros for AutoCAD LT

01-10-2013 10:20 AM 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.

Valued Mentor
bgingerich
Posts: 276
Registered: ‎08-29-2011
Message 7 of 24 (3,928 Views)

Re: Replacing LISP with Macros for AutoCAD LT

01-10-2013 10:33 AM 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
*Expert Elite*
Charles_Shade
Posts: 8,204
Registered: ‎04-10-2005
Message 8 of 24 (3,922 Views)

Re: Replacing LISP with Macros for AutoCAD LT

01-10-2013 11:32 AM 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. :smileywink:)

Regards, Charles Shade            Win8 FAQ
CSHADEDESIGN|AUTOCAD LT|LT-KB|DYNAMIC BLOCKS

 
Please mark Accept as Solution if your question is answered. Kudos gladly accepted.
Valued Mentor
bgingerich
Posts: 276
Registered: ‎08-29-2011
Message 9 of 24 (3,911 Views)

Re: Replacing LISP with Macros for AutoCAD LT

01-10-2013 12:00 PM in reply to: Charles_Shade

Are you just too lazy to do it yourself, Charles? :smileytongue:

 

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. :smileyhappy:

 

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

─────────────────────────────────────────────────────────────────────────────────────────────
Brandon Gingerich
*Expert Elite*
Charles_Shade
Posts: 8,204
Registered: ‎04-10-2005
Message 10 of 24 (3,901 Views)

Re: Replacing LISP with Macros for AutoCAD LT

01-10-2013 01:48 PM in reply to: bgingerich

2 kudos for that!

Regards, Charles Shade            Win8 FAQ
CSHADEDESIGN|AUTOCAD LT|LT-KB|DYNAMIC BLOCKS

 
Please mark Accept as Solution if your question is answered. Kudos gladly accepted.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!