vl-cmdf
 
 
 

Executes an AutoCAD command

Arguments

(vl-cmdf  [arguments] ...)

The vl-cmdf function is similar to the command function, but differs from command in the way it evaluates the arguments passed to it. The vl-cmdf function evaluates all the supplied arguments before executing the AutoCAD command, and will not execute the AutoCAD command if it detects an error during argument evaluation. In contrast, the command function passes each argument in turn to AutoCAD, so the command may be partially executed before an error is detected.

If your command call includes a call to another function, vl-cmdf executes the call before it executes your command, while command executes the call after it begins executing your command.

Some AutoCAD commands may work correctly when invoked through vl-cmdf, while failing when invoked through command. The vl-cmdf function mainly overcomes the limitation of not being able to use get.xxx functions inside command.

Arguments

arguments

AutoCAD commands and their options.

The arguments to the vl-cmdf 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 vl-cmdf with no argument is equivalent to pressing ESC and cancels most AutoCAD commands.

Return Values

T

Note that if you issue vl-cmdf from Visual LISP, focus does not change to the AutoCAD window. If the command requires user input, you'll see the return value (T) 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.

Examples

The differences between command and vl-cmdf are easier to see if you enter the following calls at the AutoCAD Command prompt, rather than the VLISP Console prompt:

Command: (command "line" (getpoint "point?") '(0 0) "")

line Specify first point: point?

Specify next point or [Undo]:

Command: nil

Using command, the LINE command executes first; then the getpoint function is called.

Command: (VL-CMDF "line" (getpoint "point?") '(0 0) "")

point?line Specify first point:

Specify next point or [Undo]:

Command: T

Using vl-cmdf, the getpoint function is called first (notice the “point?” prompt from getpoint); then the LINE command executes.

The following examples show the same commands, but pass an invalid point list argument to the LINE command. Notice how the results differ:

Command: (command "line" (getpoint "point?") '(0) "")

line Specify first point: point?

Specify next point or [Undo]:

Command: ERASE nil

Select objects: Specify opposite corner: *Cancel*

0 found

The command function passes each argument in turn to AutoCAD, without evaluating the argument, so the invalid point list is undetected.

Command: (VL-CMDF "line" (getpoint "point?") '(0) "")

point?Application ERROR: Invalid entity/point list.

nil

Because vl-cmdf evaluates each argument before passing the command to AutoCAD, the invalid point list is detected and the command is not executed.

See Also