command
 
 
 

Executes an AutoCAD command

(command [arguments] ...)

Arguments

arguments

AutoCAD commands and their options.

The arguments to the command function can be strings, reals, integers, or points, as expected by the prompt sequence of the executed command. A null string ("") is equivalent to pressing ENTER on the keyboard. Invoking command with no argument is equivalent to pressing ESC and cancels most AutoCAD commands.

The command function evaluates each argument and sends it to AutoCAD in response to successive prompts. It submits command names and options as strings, 2D points as lists of two reals, and 3D points as lists of three reals. AutoCAD recognizes command names only when it issues a Command prompt.

Note that if you issue command from Visual LISP, focus does not change to the AutoCAD window. If the command requires user input, you'll see the return value (nil) in the Console window, but AutoCAD will be waiting for input. You must manually activate the AutoCAD window and respond to the prompts. Until you do so, any subsequent commands will fail.

Return Values

nil

Examples

The following example sets two variables pt1 and pt2 equal to two point values 1,1 and 1,5. It then uses the command function to issue the LINE command in the Command Reference and pass the two point values.

Command: (setq pt1 '(1 1) pt2 '(1 5))

(1 5)

Command: (command "line" pt1 pt2 "")

line From point:

To point:

To point:

Command: nil

Restrictions and Notes

The AutoCAD SKETCH command in the Command Reference reads the digitizer directly and therefore cannot be used with the AutoLISP command function. If the SCRIPT command is used with the command function, it should be the last function call in the AutoLISP routine.

Also, if you use the command function in an acad.lsp or .mnl file, it should be called only from within a defun statement. Use the S::STARTUP function to define commands that need to be issued immediately when you begin a drawing session.

For AutoCAD commands that require the selection of an object (like the BREAK and TRIM commands in the Command Reference), you can supply a list obtained with entsel instead of a point to select the object. For examples, see Passing Pick Points to AutoCAD Commands in the AutoLISP Developer's Guide.

Commands executed from the command function are not echoed to the command line if the CMDECHO system variable (accessible from setvar and getvar) is set to 0.

See Also