command-s (AutoLISP)

Executes an AutoCAD command and the supplied input

Supported Platforms: Windows and Mac OS

Signature

(command-s [cmdname [arguments ...]])
cmdname

Type: String

Name of the command to execute.

arguments

Type: Integer, Real, String, or List

The command input to supply to the command being executed.

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.

Return Values

Type: nil

nil is returned by the function when the command is done executing on the provided arguments. An *error* is returned when the function fails to complete successfully.

Remarks

See the sections later in this topic for more information.

Examples

The following example demonstrates how to execute the AutoCAD CIRCLE command and create a circle with a diameter of 2.75.

Command: (command-s "._circle" "5,4" "_d" 2.75)
nil

The following example demonstrates how to prompt the user for the center point of the circle.

Command: (setq cPt (getpoint "\nSpecify center point: "))
(5.0 4.0 0.0)

Command: (command-s "._circle" cPt "_d" 2.75)
nil

The following is an invalid use of prompting for user input with the command-s function.

Command: (command-s "._circle" (getpoint "\nSpecify center point: ") "_d" 2.75)

Differences from the Command Function

The command-s function is a variation of the command function which has some restrictions on command token content, but is both faster than command and can be used in *error* handlers due to internal logic differences.

A command token is a single argument provided to the command-s function. This could be a string, real, integer, point, entity name, list, and so on. The following example shows the AutoCAD LINE command and three command tokens:

(command-s "._line" "0,0" "5,7" "")

The "-s" suffix stands for "subroutine" execution of the supplied command tokens. In this form, AutoCAD is directly called from AutoLISP, processes the supplied command tokens in a temporary command processor distinct from the main document command processor, and then returns, thus terminating the temporary command processor. The command that is being executed must be started and completed in the same command-s function.

In contrast, the command function remains a "co-routine" execution of the supplied command tokens, where AutoLISP evaluates the tokens one at a time, sending the result to AutoCAD, and then returning to allow AutoCAD to process that token. AutoCAD then calls AutoLISP back, and AutoLISP resumes evaluation of the expression in progress. In this logic flow, subsequent token expressions can query AutoCAD for the results of previous token processing and use it.

In summary, the "co-routine" style of command token processing is more functionally powerful, but is limited in when it can be used when running. The "subroutine" style of command token processing can be used in a much wider range of contexts, but processes all command tokens in advance, and actual execution is non-interactive. For the same set of command tokens, command-s function is significantly faster.

Known Considerations

When using the command-s function, you must take the following into consideration:

Caution: Although the command-s function is similar to the command function, caution should be taken when using U or UNDO to roll back the system state if there is an AutoCAD command already in progress when the AutoLISP expression is entered. In that case, the results of running UNDO may cause the command in progress to fail or even crash AutoCAD.

*error* Handler

If your *error* handler uses the command function, consider updating the way you define your custom *error* handlers using the following methods: