AutoLISP.4 :(command ..) function



Author Orhan Toker
Profession Architect M.Sc.
  Autodesk Authorized Consultant
  Database Specialist
e-mail  

All AutoLISP versions

Hello,

In this lesson, I will explain the (command) function. As you know, although AutoLISP is a programming language much more than a scripting language, it is mainly used to write scripts in AutoCAD. As we also started from the beginning, in order to have AutoCAD to execute such scripts, we will start from the easiest way of doing this which is the (command) function. (command) function is used to send commands directly to AutoCAD command line. (command) function uses different types and numbers of arguments depending up on the AutoCAD command. Data like angles, distances and points can either be passed inside quotation marks or directly as numbers into the arguments of (command) function. An empty string “” that you pass into the AutoCAD command line will act same as ENTER or SPACE. As an exception, SKETCH command and c:nnn lisp functions that is defined as AutoCAD commands can not be used in (command) functions. Here is some examples about using (command) function.

(command "line" "0,0" "3,3")
(command "thickness" 1)
(setq p1 '(1.0 1.0 3.0))
(setq rad 4.5)
(command "circle" p1 rad)

Foreign Language Support

If you want your program to work in all other versions of AutoCAD in other languages, you should use underscore character (_) while calling AutoCAD commands with (command) functions. For example:

(command "_line" pt1 pt2 pt3 "_c")

In addition to this information, if you would like to avoid AutoCAD commands that may be possibly re-defined by the user, you should use dot character (.). You can use both of them together of separately.

(command "._line" pt1 pt2 pt3 "_c")
(command "_.line" pt1 pt2 pt3 "_c")
(command ".line" pt1 pt2 pt3 "c")

Pausing for the user to enter data

During the execution of command, in order to prompt the user to pick points or stretch, PAUSE variable is used as an argument. This is same as the backslash (\) symbol in the menus. Let me explain this with an example:

(command "._circle" PAUSE 50.0)

When you enter this line into the command line, AutoCAD will enter circle command and will pause by prompting you to enter the center of the circle. As soon as you pick a point, it will draw a circle having the center as the point you have picked and the radius as 50.

PS: If you have interrupted the execution of command by PAUSE, you can use the transparent commands during this pause. In the previous example, when AutoCAD pauses for you to enter the center, you can use ‘zoom or ‘pan transparent commands. Although this information is obsolete with the use of wheel of mouse, I just found it useful to write it.

Important: If you have used PAUSE to enter ATTRIBUTE or TEXT, AutoCAD will only wait for data entry unless the TEXTEVAL system variable is 0. If TEXTEVAL is equal to 0, PAUSE will not work!

Passing (PICK POINTS) into (command) function

In commands like TRIM, EXTEND and FILLET, both selecting entity and determination of selection point is done together. In such cases, passing of both the selected entity and the selection point data to the (command) function is not possible by PAUSE argument. Instead, these data should be stored inside variables prior to the command. You can see how it is done in the following example:

(command "._circle" "5,5" "2") ; draws the circle
(command "._line" "3,5" "7,5" "") ; draws the line
(setq el (entlast)) ; stores the entity drawn last in “el” variable
(setq pt '(5 7)); stores the selection point in “pt” variable
(command "trim" el "" pt "") ; trim command is executed

You should be careful for such operations.

• Entities and Pick point over which the command is executed should be inside the model window during the execution of command.
• If necessary, you can increase “PICKBOX” system variable a little bit.

That’s all for this lesson. It is a good practice to try the examples by your self.

Technorati Tags: , ,

Similar Posts

Rate this article:

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

2 Responses to “AutoLISP.4 :(command ..) function

  • 1
    Brian VanAllen
    June 29th, 2007 22:02

    Thanks for your posting on AutoLISP.4 :(command ..) function. I’ve understood 99% of it for some time now, but was not aware of your important note about Texteval needing to be off in order to pause for attributes. That has been holding me back and nowhere else I’ve found on the web has that been mentioned regarding pause.

    Such a simple fix, thanks again.

    ps. I don’t suppose you may know why setvar will sometimes not work when command in its place will?
    [ie. (setvar “osmode” 0) sometimes won’t work but (command “osmode” 0) will]

  • 2
    mohammad
    July 10th, 2007 22:01

    i want know how to change the numbers inside the attribute automaticly without putting the numbers

Leave a Reply