AutoCAD/Keystroke command

Advertisement


Question
I had in my acad.lsp file several keystroke commands similiar to acad.pgp. I forgot to make a backup file and overwrote the lsp file when I installed ver 2004.  I can't remember how the lisp defun was typed in my acad.lsp file.

Here is what I used to have....

command:LEE  
would be line (endpoint)(endpoint)
or

command:LCP
would be line (center)(perpendicular)

I had made several of these for a one time use of my line command.  I don't like to have osnap on all of the time and these worked great for me.

I've tried to add them to my acad.lsp file but I can't get them to work.  I get the first point but not the second. I get a bad function error

Here is how I am putting it into my lsp file...

(defun c:lcc()(command"line""cen")("cen"))

for a line center to center

I remember it was similiar to this.

Can you help me?
Thanks
Steve

Answer
Steve:  What you are doing is exactly how I got started in LISP for AutoCAD.  

(defun c:lcc () (command "_.line" "cen" pause "cen" pause "")(princ))

As you already know, c:lcc is the name of the function which you can use as a command.  The () parentheses can contain words called local variables and arguments.  More LISP study will help you with that. The underscore before the line command is so that the routine or macro can be used even in international versions of AutoCAD in other languages.  The dot means that if the line command has been redefined, it will refer to only AutoCAD's version of the line command.  In this case, everything in quotes is what a user would type at the command line to accomplish what he needs done.  The pauses refer to user input.  It could be typed in or picked with the mouse.  In the case of this macro, the user input will be made with the mouse.  The (princ) function cleans up AutoLISP messaging so that it doesn't return "nil" at the command line when you are done with the function.

See if that is enough to get you by for now, using the same principles in the rest of your macros in ACAD.LSP.

Keep in touch
Bill DeShawn
http://my.sterling.net/~bdeshawn

AutoCAD

All Answers


Answers by Expert:


Ask Experts

Volunteer


Bill DeShawn

Expertise

I can address all 2-D questions and some 3-D questions. I do programming in AutoLISP if it doesn`t involve solid modeling. I can also address menu customization issues and can help you find answers to questions I can`t answer by taking your question directly to Autodesk via their newsgroups.

Experience

I used to do electronic and mechanical design for a flat panel monitor manufacturer, and now I do architectural drafting for an architect. I did and do AutoLISP and menu customization and take pride in making my lisp routines to do the work exactly the way the client likes them done.

Publications
I had a routine published in CADENCE magazine (no longer in publication and taken over by CADALYST). Some of my routines are published on my website at http://my.sterling.net/~bdeshawn

©2012 About.com, a part of The New York Times Company. All rights reserved.