AutoCAD 2002 Bible

Скачать в pdf «AutoCAD 2002 Bible»

Accessing AutoCAD commands


In the previous chapter when you looked at an AutoLISP routine (see Figure 34-5), you saw an example of the COMMAND function. You use the COMMAND function in AutoLISP to execute AutoCAD commands. This function treats all subsequent operands as if they were typed at the command line interactively. When programming COMMAND functions in AutoLISP, exactly duplicate what you would do at the command line. For example, to draw a line, you follow the steps shown in the following table. The second column shows how you would accomplish the same action in an AutoLISP routine.


Enter line at the    «line» (or «_line»)


command line


Specify the start    Use a variable, actual coordinates, or pause for user


point for the line    input.


Specify the endpoint Use a variable, actual coordinates, or pause for user


input.


Press Enter to end    Use an empty set of two quotation marks to


the LINE command    represent pressing Enter within a command or to


end a command.


For example, if you are using the variables startpt and endpt for the start point and endpoint of a line, here’s how you would access the LINE command in an AutoLISP expression:


(command «_line» startpt endpt «»)

Creating functions


Functions always begin with the operator DEFUN. You can define three principal types of functions:


♦    The type you have been using thus far precedes the command name defined by defun with c:, which is interpreted by AutoCAD as a command and enables you to use the function by name at the AutoCAD command line. The function becomes usable like any other AutoCAD command.

Скачать в pdf «AutoCAD 2002 Bible»