Satish Lele
satish.lele@gmail.com


AutoLISP FUNCTIONS with EXAMPLES
A B C D E F G H I L M N
O P Q R S T U V W X Z

The following is a list of all standard AutoLISP functions that are defined by AutoCAD. The functions are listed alphabetically. Each listing contains a brief description of the function's use and a function syntax statement showing the order and the type of arguments required by the function. The number argument needs additional information: a number can be a real number, an integer, or a symbol set to a real or integer value. If all arguments are integers, the result is an integer. If any of the arguments are real numbers, the integers are promoted to real numbers and the result is a real number.
Operators       +     -     *     /     =    /=    <    <=     >    >=     ~    1+    1-  
+ (addition): Returns the sum of all numbers
(+ [number number] ...)
If you supply only one number argument, this function returns the result of adding it to zero. It returns the number. Supplying no arguments returns 0.
(+ 1 2): returns 3
(+ 1 2 3 4.5): returns 10.5
(+ 1 2 3 4.0): returns 10.0
- (subtraction): Subtracts the second and following numbers from the first and returns the difference (- [number number] ...)
If you supply more than two number arguments, this function returns the result of subtracting the sum of the second through last numbers from the first number. If you supply only one number argument, this function returns the result of subtracting it from zero or it returns the number. Supplying no arguments returns 0.
(- 50 40): returns 10
(- 50 40.0): returns 10.0
(- 50 40.0 2.5): returns 7.5
(- 8): returns -8
* (multiplication): Returns the product of all numbers.
(* [number number] ...)
If you supply only one number argument, this function returns the result of multiplying it by one or it returns the number. Supplying no arguments returns 0.
(* 2 3): returns 6
(* 2 3.0): returns 6.0
(* 2 3 4.0): returns 24.0
(* 3 -4.5): returns -13.5
(* 3): returns 3
/ (division): Divides the first number by the product of the remaining numbers and returns the quotient.
(/ [number number] ...)
If you supply more than two number arguments, this function divides the first number by the product of the second through last numbers, and returns the final quotient. If you supply only one number argument, this function returns the result of dividing it by one or it returns the number. Supplying no arguments returns 0.
(/ 100 2): returns 50
(/ 100 2.0): returns 50.0
(/ 100 20.0 2): returns 2.5
(/ 100 20 2): returns 2
(/ 4): returns 4
= (equal to): Returns T if all arguments are numerically equal, and returns nil otherwise.
(= numstr [numstr] ...)
Each numstr argument can be a number or a string.
(= 4 4.0): ;returns T
(= 20 388): ;returns nil
(= 2.4 2.4 2.4): ;returns T
(= 499 499 500): returns nil
(= "me" "me"): returns T
(= "me" "you"): returns nil
(See also the eq and equal functions)
/= (not equal to): Returns T if the arguments are not numerically equal, and nil if the arguments are numerically equal.
(/= numstr [numstr] ...)
Each numstr argument can be a number or a string.
(/= 10 20): returns T
(/= "you" "you") returns nil
(/= 5.43 5.44): returns T
(/= 10 20): returns T
< (less than): Returns T if each argument is numerically less than the argument to its right, and returns nil otherwise.
(< numstr [numstr] ...)
Each numstr argument can be a number or a string.
(< 10 20): returns T
(< "b" "c"): returns T
(< 357 33.2): returns nil
(< 2 3 88): returns T
(< 2 3 4 4): returns nil
<= (less than or equal to): Returns T if each argument is numerically less than or equal to the argument to its right, and returns nil otherwise.
(<= numstr [numstr] ...)
Each numstr argument can be a number or a string.
(<= 10 20): returns T
(<= "b" "b"): returns T
(<= 357 33.2): returns nil
(<= 2 9 9): returns T
(<= 2 9 4 5): returns nil
> (greater than): Returns T if each argument is numerically greater than the argument to its right, and returns nil otherwise.
(> numstr [numstr] ...)
Each numstr argument can be a number or a string.
(> 120 17): returns T
(> "c" "b"): returns T
(> 3.5 1792): returns nil
(> 77 4 2): returns T
(> 77 4 4): returns nil
>= (greater than or equal to): Returns T if each argument is numerically greater than or equal to the argument to its right, and returns nil otherwise.
(>= numstr [numstr] ...)
Each numstr argument can be a number or a string.
(>= 120 17): returns T
(>= "c" "c"): returns T
(>= 3.5 1792): returns nil
(>= 77 4 4): returns T
(>= 77 4 9): returns nil
~ (bitwise NOT): Returns the bitwise NOT (1's complement) of the argument.
(~ int)
(~ 3): returns -4
(~ 100): returns -101
(~ -4): returns 3
1+ (increment): Returns the argument increased by 1 (incremented)
(1+ number)
(1+ 5): returns 6
(1+ -17.5): returns -16.5
1- (decrement): Returns the argument reduced by 1 (decremented).
(1- number)
(1- 5): returns 4
(1- -17.5): returns -18.5

A   abs     acad_colordlg     acad_strlsort     action_tile     add_list     ads     alert     alloc     and     angle     angtof     angtos     append     apply     arx     arxload      arxunload     ascii     assoc     atan     atof     atoi     atom     atoms-family     autoarxload     autoload     autoxload  
abs: Returns the absolute value of the argument.
(abs number)
(abs 100): returns 100
(abs -100): returns 100
(abs -99.25): returns 99.25
acad_colordlg: Displays the standard AutoCAD color selection dialog box.
(acad_colordlg colornum [flag])
The colornum argument is an integer in the range 0-256 (inclusive). It specifies the AutoCAD color number to display as the initial default. A colornum value of 0 defaults to BYBLOCK, and a value of 256 defaults to BYLAYER. Setting the optional flag argument to nil disables the BYLAYER and BYBLOCK buttons. Omitting the flag argument or setting it to a non-nil value enables the BYLAYER and BYBLOCK buttons. The acad_colordlg function returns the user-selected color number. If the user cancels the dialog box, acad_colordlg returns nil. The following code prompts the user to select a color and specifies a default of green: (acad_colordlg 3) Externally defined function acadapp ARX application.
acad_strlsort: Sorts a list of strings by alphabetical order.
(acad _strlsort list)
The list argument is the list of strings to be sorted. The acad_strlsort function returns a list of the same strings in alphabetical order. If the list argument list is invalid or if there isn't enough memory to do the sort, acad_strlsort returns nil.
The following code sorts the list of abbreviated month names:
(setq mos '("Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"))
(acad_strlsort mos)
It returns the following list:
("Apr" "Aug" "Dec" "Feb" "Jan" "Jul" "Jun" "Mar" "May" "Nov" "Oct" "Sep")
Externally defined function acadapp ARX application action_tile: Assigns an action to evaluate when the user selects the specified tile in a dialog box.
(action_tile key action-expression)
The key and action-expression arguments are strings. The key argument is the name of the tile that triggers the action (specified as its key attribute). The key argument is case sensitive. The action-expression is evaluated when the tile is selected. The action assigned by action_tile supersedes the dialog box's default action (assigned by new_dialog) or the tile's action attribute, if these are specified. The expression can refer to the tile's current value (its value attribute) as $value, its name as $key, its application-specific data (as set by client_data_tile) as $data, its callback reason as $reason, and its image coordinates (if the tile is an image button) as $x and $y. You cannot call the AutoLISP command function from the action_tile function.
(See also "Default and DCL Actions")
add_list: Adds or modifies a string in the currently active dialog box list.
(add_list string)
Before using add_list, you must open the list and initialize it with a call to start_list. Depending on the operation specified in start_list, the string either is added to the current list or replaces the current list item. Assuming that the currently active DCL file has a popup_list or list_box with a key of longlist, the following code fragment initializes the list and adds to it the text strings in llist.
(setq llist '("first line" "second line" "third line"))
(start_list "longlist")
(mapcar 'add_list llist)
(end_list)
After the list has been defined, the following code fragment changes the text in the second line to "2nd line".
(start_list "longlist" 1 0)
(add_list "2nd line")
(end_list)
(See also the start_list and end_list functions)
ads: Returns a list of the currently loaded ADS applications.
(ads) Each application and its path is a quoted string in the list. (ads) might return ("files/progs/PROG1" "PROG2")
(See also the xload and xunload functions)
alert: Displays an alert box with the error or warning message passed as a string.
(alert string)
An alert box is a dialog box with a single OK button.
(alert "That function is not available.")
You can display multiple lines by using the newline character in string.
(alert "That function\nis not available.")
Note Line length and the number of lines in an alert box are platform, device, and window dependent. AutoCAD truncates any string that is too long to fit inside an alert box.
alloc: Sets the segment size to a given number of nodes.
(alloc int)
This function returns the previous segment size.
(See also "Manual Allocation")
and: Returns the logical AND of a list of expressions.
(and expr ...)
If any of the expressions evaluate to nil, this function ceases further evaluation and returns nil; otherwise it returns T.
For example, given the assignments
(setq a 103 b nil c "string")
then
(and 1.4 a c): returns T
(and 1.4 a b c): returns nil
angle: Returns an angle in radians of a line defined by two endpoints.
(angle pt1 pt2)
The angle is measured from the X axis of the current construction plane, in radians, with angles increasing in the counterclockwise direction. If 3D points are supplied, they are projected onto the current construction plane.
(angle '(1.0 1.0) '(1.0 4.0)) returns 1.5708
(angle '(5.0 1.33) '(2.4 1.33) returns 3.14159
(See also "Angular Conversion")
angtof: Converts a string representing an angle into a real (floating-point) value in radians.
(angtof string [mode])
The string argument describes an angle based on the format specified by the mode argument. The mode argument, shown in the following table, specifies the units in which the string is formatted. The value should correspond to values allowed for the AutoCAD system variable AUNITS. If mode is omitted, angtof uses the current value of AUNITS.
Mode value;String format
0;;Degrees
1;;Degrees/minutes/seconds
2;;Grads
3;;Radians
4;;Surveyor's units
The string must be a string that angtof can parse correctly to the specified mode. It can be in the same form that angtos returns, or in a form that AutoCAD allows for keyboard entry. The angtof and angtos functions are complementary: if you pass angtof a string created by angtos, angtof is guaranteed to return a valid value, and vice versa (assuming the mode values match). If angtof succeeds, it returns a real value in radians; otherwise it returns nil.
angtos: Converts an angular value in radians into a string.
(angtos angle [mode [precision]])
The angtos function takes angle (a real number, in radians) and returns it edited into a string according to the settings of mode, precision, the AutoCAD UNITMODE system variable, and the DIMZIN dimensioning variable. The mode and precision arguments are integers that specify the angular units mode and precision. Mode value;String format
0;;Degrees
1;;Degrees/minutes/seconds
2;;Grads
3;;Radians
4;;Surveyor's units
The precision argument is an integer that selects the number of decimal places of precision desired. The mode and precision correspond to the AutoCAD system variables AUNITS and AUPREC. If you omit these arguments, angtos uses the current settings of AUNITS and AUPREC, respectively. The angtos function accepts a negative angle argument, but always reduces it to a positive value between zero and 2 pi radians before performing the specified conversion.
(angtos 0.785398 0 4): returns "45.0000"
(angtos -0.785398 0 4): returns "315.0000"
The UNITMODE variable affects the returned string when surveyor's units are selected (a mode value of 4). If UNITMODE = 0, spaces are included in the string (for example, "N 45d E"); if UNITMODE = 1, no spaces are included in the string (for example, "N45dE"). Routines that use the angtos function to display arbitrary angles (those not relative to the value of ANGBASE) should check and consider the value of ANGBASE.
(See also "String Conversions")
append: Takes any number of lists and runs them together as one list.
(append list ...)
(append '(a b) '(c d)): returns (A B C D)
(append '((a)(b)) '((c)(d))): returns ((A)(B)(C)(D))
apply: Passes a list of arguments to a specified function.
(apply 'function list)
The apply function works with both built-in functions (subrs) and user-defined functions (those created with either defun or lambda).
(apply '+ '(1 2 3)): returns 6
(apply 'strcat '("a" "b" "c")): returns "abc"
arx: Returns a list of the currently loaded ARX applications.
(arx)
Each application and its path is a quoted string in the list.
(arx) might return ("files/progs/PROG1" "PROG2")
(See also the arxload and arxunload functions)
arxload: Loads an ARX application.
(arxload application [onfailure])
The application argument is entered as a quoted string or as a variable that contains the name of an executable file. At the time the file is loaded, it is verified to be a valid ARX application. If the arxload operation fails, it normally causes an AutoLISP error. However, if the onfailure argument is supplied, arxload returns the value of this argument upon failure instead of an error message.If the application is successfully loaded, the application name is returned. (arxload "/myapps/appx") if successful, returns "/myapps/appx". If you attempt to load an application that is already loaded, arxload issues the following message and returns the application name. Application "application" already loaded. You may want to check the currently loaded ARX applications with the arx function before using arxload.
arxunload: Unloads an ARX application.
(arxunload application [onfailure])
If the application is successfully unloaded, the application name is returned, otherwise, an error message is issued. Enter application as a quoted string or as a variable containing the name of an application that was loaded with the arxload function. The application name must be entered exactly as it was entered for the arxload function. If a path (directory name) or extension was entered for the application in arxload, it can be omitted in the arxunload function. For example, the following code unloads the application appx, which was previously loaded with the arxload function: (arxunload "appx") if successful, returns "appx". If the arxunload operation fails, it normally causes an AutoLISP error. However, if the onfailure argument is supplied, arxunload returns the value of this argument upon failure instead of issuing an error message. This feature of arxunload is similar to that in the arxload function.
ascii: Returns the conversion of the first character of a string into its ASCII character code (an integer).
(ascii string)
(ascii "A"): returns 65
(ascii "a"): returns 97
(ascii "BIG"): returns 66
This is similar to the ASC function in the BASIC language.
assoc: Searches an association list for an element and returns that association list entry.
(assoc item alist)
Searches the association list alist for item as the key element and returns the alist entry. If assoc does not find item as a key in alist, it returns nil.
For example, given the code:
(setq al '((name box) (width 3) (size 4.7263) (depth 5)))
then
(assoc 'size al): returns (SIZE 4.7263)
(assoc 'weight al): returns nil
Association lists are frequently used for storing data that can be accessed by a key. The subst function provides a convenient means of replacing the value associated with one key in an association list.
atan: Returns the arctangent of a number in radians.
(atan num1 [num2])
If you supply only one argument to atan, it returns the arctangent of num1, in radians. If you supply both num1 and num2 arguments, atan returns the arctangent of num1/num2, in radians. If num2 is zero, it returns an angle of plus or minus 1.570796 radians (+90 degrees or -90 degrees), depending on the sign of num1. The range of angles returned is -pi/2 to +pi/2 radians.
(atan 0.5) returns 0.463648
(atan 1.0) returns 0.785398
(atan -1.0) returns -0.785398
(atan 2.0 3.0) returns 0.588003
(atan 2.0 -3.0) returns 2.55359
(atan 1.0 0.0) returns 1.5708
Note The angtos function converts the radian value returned from atan into a string value.
(angtos (atan -1.0) 0 4) returns "315.0000"
(angtos (atan 2.0 3.0) 0 4) returns "33.6901"
(angtos (atan 2.0 -3.0) 0 4) returns "146.3099"
(angtos (atan 1.0 0.0) 0 4) returns "90.0000"
atof: Returns the conversion of a string into a real.
(atof string)
(atof "97.1"): returns 97.1
(atof "3"): returns 3.0
(atof "3.9"): returns 3.9
atoi: Returns the conversion of a string into an integer.
(atoi string)
(atoi "97"): returns 97
(atoi "3"): returns 3
(atoi "3.9"): returns 3
atom: Verifies that an item is an atom.
(atom item)
Returns nil if item is a list, and returns T otherwise. Anything that's not a list is considered an atom.
For example, given the assignments
(setq a '(x y z))
(setq b 'a)
then
(atom a) returns T
(atom 'a) returns nil
(atom b) returns T
(atom 'b) returns nil
(atom '(a b c)) returns nil
Some versions of LISP differ in their interpretation of atom, so take care when using converted code.
atoms-family: Returns a list of the currently defined symbols.
(atoms-family format [symlist])
The format argument is an integer value of 0 or 1. If the value of format is 0, atoms-family returns the symbol names as a list. If format is 1, it returns the symbol names as a list of strings. The atoms-family function searches for a specific list of symbol names if you supply the symlist argument. The symlist argument is a list of strings that specify the symbol names. The atoms-family function returns a list of the type that is specified by format (symbols or strings) and that contains the names of the symbols that are defined. It returns nil for those that are not defined. (atoms-family 0) returns a list of the currently defined symbols. The following code verifies that the symbols CAR, CDR, and XYZ have been defined, and returns the list as strings:
(atoms-family 1 '("CAR" "CDR" "XYZ")) returns ("CAR" "CDR" nil)
The preceding return value shows that the symbol XYZ has not been defined.
autoarxload: Predefines command names to load an associated ARX file.
(autoarxload filename cmdlist)
The filename argument is a string that specifies the .arx file that is loaded when one of the commands defined by the cmdlist argument is entered at the Command prompt. The cmdlist argument must be a list of strings. The autoarxload function returns nil. The following code defines the C:APP1, C:APP2, and C:APP3 functions to load the bounsapp.arx file. The first time one of the command, APP1, APP2, or APP3 are entered at the Command prompt the ARX application loads and the command continues. (autoarxload "BONUSAPP" '("APP1" "APP2" "APP3")). Warning The commands listed by the cmdlst argument must be defined as commands by the file specified by filename.
autoload: Predefines command names to load an associated AutoLISP file.
(autoload filename cmdlist)
The filename argument is a string that specifies the .lsp file that is loaded when one of the commands defined by the cmdlist argument is entered at the Command prompt. The cmdlist argument must be a list of strings. The autoload function returns nil. The following code defines the C:APP1, C:APP2, and C:APP3 functions to load the bounsapp.lsp file. The first time one of the command, APP1, APP2, or APP3 are entered at the Command prompt the AutoLISP file loads and the command continues.
(autoload "BONUSAPP" '("APP1" "APP2" "APP3")). Warning The commands listed by the cmdlst argument must be defined as commands by the file specified by filename.
autoxload: Predefines command names to load an associated ADS application.
(autoxload filename cmdlist)
The filename argument is a string that specifies the ADS application that is loaded when one of the commands defined by the cmdlist argument is entered at the Command prompt. The cmdlist argument must be a list of strings. The autoxload function returns nil. The following code defines the C:APP1, C:APP2, and C:APP3 functions to load the bounsapp ADS application. The first time one of the command, APP1, APP2, or APP3 is entered at the Command prompt the ADS application loads and the command continues. (autoxload "BONUSAPP" '("APP1" "APP2" "APP3")).
Warning The commands listed by the cmdlst argument must be defined as commands by the file specified by filename.

B  boole     boundp  
Boole: Serves as a general bitwise Boolean function.
(Boole func int1 int2 ...)
The func argument is an integer between 0 and 15 representing one of the 16 possible Boolean functions in two variables. Successive integer arguments are bitwise (logically) combined based on this function and on the following truth table.
Boolean truth table.
Int1 : Int2 : Func bit.
0 : 0 : 8
0 : 1 : 4
1 : 0 : 2
1 : 1 : 1
Each bit of int1 is paired with the corresponding bit of int2, specifying one horizontal row of the truth table. The resulting bit is either 0 or 1, depending on the setting of the func bit that corresponds to this row of the truth table. If the appropriate bit is set in func, the resulting bit is 1; otherwise the resulting bit is 0. Some of the values for func are equivalent to the standard Boolean operations AND, OR, XOR, and NOT.
Boole function bit values
Func : Operation : Resulting bit is 1 if...
1 : AND : Both input bits are 1
6 : XOR : Only one of the two input bits is 1
7 : OR : Either or both of the input bits are 1
8 : NOR : Both input bits are 0 (1's complement)
The following specifies a logical AND of the values 12 and 5:
(Boole 1 12 5): returns 4
Similarly, the following specifies a logical XOR of the values 6 and 5:
(Boole 6 6 5): returns 3
You can use other values of func to perform other Boolean operations for which there are no standard names. For example, if func is 4, the resulting bits are set if the corresponding bits are set in int2 but not in int1. Thus
(Boole 4 3 14): returns 12
Boundp: Verifies if a value is bound to a symbol.
(boundp sym)
Returns T if sym has a value bound to it. If no value is bound to sym (or if it has been bound to nil), boundp returns nil. If sym is an undefined symbol, it is automatically created and is bound to nil. For example, given the assignments.
(setq a 2 b nil)
then
(boundp 'a) returns T
(boundp 'b) returns nil
The atoms-family function provides an alternate method of determining the existence of a symbol without automatically creating the symbol.

C   car and cdr     chr     close     command     cond     cons     cos     cvunit  
car and cdr: Returns the first element of a list or a list containing all but the first element of a list.
(car list) and (cdr list)
If list is empty, car returns nil.
(car '(a b c)): returns A
(car '((a b) c)): returns (A B)
(car '()): returns nil
If list is empty, cdr: returns nil.
(cdr '(a b c)): returns (B C)
(cdr '((a b) c)): returns (C)
(cdr '()): returns nil
When the list argument is a dotted pair (see "cons"), cdr returns the second element without enclosing it in a list.
(cdr '(a . b)) returns B
(cdr '(1 . "Text")) returns "Text"
AutoLISP supports concatenations of car and cdr up to four levels deep. The following are valid functions:
caaaar: cadaar: cdaaar: cddaar
caaadr: cadadr: cdaadr: cddadr
caaar: cadar: cdaar: cddar
caadar: caddar: cdadar: cdddar
caaddr: cadddr: cdaddr: cddddr
caadr: caddr: cdadr: cdddr
caar: cadr: cdar: cddr
These concatenations are the equivalent of nested calls to car and cdr. Each a represents a call to car, and each d represents a call to cdr. For example:
(caar x) is equivalent to (car (car x))
(cdar x) is equivalent to (cdr (car x))
(cadar x) is equivalent to (car (cdr (car x)))
(cadr x) is equivalent to (car (cdr x))
(cddr x) is equivalent to (cdr (cdr x))
(caddr x) is equivalent to (car (cdr (cdr x)))
In AutoLISP, cadr is frequently used to obtain the Y coordinate of a 2D or 3D point (the second element of a list of two or three reals). Likewise, caddr can be used to obtain the Z coordinate of a 3D point. For instance, given the assignments
(setq pt2 '(5.25 1.0)) a 2D point
(setq pt3 '(5.25 1.0 3.0)) a 3D point
then
(car pt2): returns 5.25
(cadr pt2): returns 1.0
(caddr pt2): returns nil
(car pt3): returns 5.25
(cadr pt3): returns 1.0
(caddr pt3): returns 3.0
chr: Returns the conversion of an integer representing an ASCII character code into a single-character string.
(chr integer)
(chr 65) returns "A"
(chr 66) returns "B"
(chr 97) returns "a"
This function is similar to the chr$ function in the BASIC language. client_data_tile: Associates application-managed data with a dialog box tile (client_data_tile key clientdata). The key argument is a string that specifies a tile. The key argument is case sensitive. The data is a string specified by the clientdata argument. An action expression or callback function can refer to the string as $data.
close: Closes an open file.
(close file-desc)
The file-desc argument is a file descriptor obtained from the open function. After a close, the file descriptor is unchanged but is no longer valid. Data added to an open file is not actually written until the file is closed. The close function returns nil if file-desc is valid, otherwise, it returns an error message. For example, the following code counts the number of lines in the file somefile.txt and sets the variable ct equal to that number.
(setq fil "SOMEFILE.TXT")
(setq x (open fil "r") ct 0)
(while (read-line x)
(setq ct (1+ ct))
(close x)
command: Executes an AutoCAD command.
(command [arguments] ...)
The arguments argument represents 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 returns nil.
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. 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. 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 and pass the two point values.
(setq pt1 '(1 1) pt2 '(1 5))
(command "line" pt1 pt2 "")
If your application is to be used with foreign language versions of AutoCAD, command names must be prefixed with an underscore (_) so they can be translated. If you are using the dot prefix (to avoid using redefined commands), you can place the dot and underscore in either order; both "._line" and "_.line" are valid. 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. The getxxx user-input functions (getangle, getstring, getint, getpoint, and so on) cannot be used inside the command function. An attempt to do so results in the following message and terminates the function in progress.

cond: Serves as the primary conditional function for AutoLISP.
(cond (test1 result1 ...) ...)
The cond function accepts any number of lists as arguments. It evaluates the first item in each list (in the order supplied) until one of these items returns a value other than nil. It then evaluates those expressions that follow the test that succeeded, and returns the value of the last expression in the sublist. If there is only one expression in the sublist (that is, if result is missing), the value of the test expression is returned. The following example uses cond to perform an absolute value calculation:
(cond
;((minusp a) (- a))
;(t a)
If the variable a is set to the value -10, this returns 10.
As shown, cond can be used as a case type function. It is common to use T as the last (default) test expression. Here's another simple example. Given a user response string in the variable s, this function tests the response and returns 1 if it is Y or y, 0 if it is N or n, and nil otherwise.
(cond
;((= s "Y") 1)
;((= s "y") 1)
;((= s "N") 0)
;((= s "n") 0)
;(t nil)
cons: The basic list constructor.
(cons new-first-element list)
The cons function takes an element (new-first-element) and a list, and returns the addition of that element to the beginning of the list. The first element can be an atom or a list.
(cons 'a '(b c d)) returns (A B C D)
(cons '(a) '(b c d)) returns ((A) B C D)
The cons function also accepts an atom in place of the list argument, constructing a structure known as a dotted pair. When displaying a dotted pair, AutoLISP prints a period, or dot, between its first and second elements. You can use the cdr function to return the second atom of a dotted pair.
(cons 'a 2) returns (A . 2)
(car (cons 'a 2)) returns A
(cdr (cons 'a 2)) returns 2
A dotted pair is a special kind of list and is not accepted as an argument by some functions that handle ordinary lists.
cos: Returns the cosine of an angle expressed in radians.
(cos ang)
(cos 0.0): returns 1.0
(cos pi): returns -1.0
cvunit: Converts a value from one unit of measurement to another.
(cvunit value from to)
The value argument is the numeric value that you want to convert. It can also be a list containing two or three numbers to be converted (a 2D or 3D point). The from argument is the unit that the value is being converted from, and to is the unit that the value is being converted into. The from and to arguments can name any unit type found in the acad.unt file. If successful, cvunit returns the converted value. If either unit name is unknown (not found in the acad.unt file), or if the two units are dimensionally incompatible (as in converting grams into years), cvunit returns nil.
(cvunit 1 "minute" "second") returns 60.0
(cvunit 1 "gallon" "furlong") returns nil
(cvunit 1.0 "inch" "cm") returns 2.54
(cvunit 1.0 "acre" "sq yard") returns 4840.0
(cvunit '(1.0 2.5) "ft" "in") returns (12.0 30.0)
(cvunit '(1 2 3) "ft" "in") returns (12.0 24.0 36.0)
Note If you have several values to convert in the same manner, it is more efficient to convert the value 1.0 once and then apply the resulting value as a scale factor in your own function or computation. This works for all predefined units except temperature, where an offset is involved as well. (See also "Unit Conversion")

D   defun     dictadd     dictnext     dictremove     dictreneme     dictsearch     distance      distof     done_dialog  
defun: Defines a function.
(defun sym argument-list expr ...)
The defun function defines a function with the name sym (the function name is automatically quoted). Following the function name is a list of arguments (possibly void), optionally followed by a slash and the names of one or more local symbols for the function. The slash must be separated from the first local symbol and from the last argument, if any, by at least one space. If you don't declare any arguments or local symbols, you must supply an empty set of parentheses after the function name.
The following argument-list examples show valid and invalid values:
(defun myfunc (x y) ...) Function takes two arguments
(defun myfunc (/ a b) ...) Function has two local symbols
(defun myfunc (x / temp) ...) One argument, one local symbol
(defun myfunc () ...) No arguments or local symbols
You cannot define a function with multiple arguments of the same name. But you can have one argument that defines a local variable with the same name as another local variable or with the same name as one of the arguments:
(defun fubar (a a / b) ...) Not legal
(defun fubar (a b / a a b) ...) Legal, but useless
If the argument/symbol list contains duplicate entries, the first occurrence of each name is used and the following occurrences are ignored. One or more expressions following the list of arguments and local symbols are evaluated when the function is executed. The defun function returns the name of the function being defined. When the defined function is invoked, its arguments are evaluated and bound to the argument symbols. You can use the local symbols within the function without changing their bindings at outer levels. The function returns the result of the last expression evaluated. All previous expressions have only side effects. The following examples define new functions with defun and show the values returned by the new functions:
(defun add10 (x)
;(+ 10 x)
)
(add10 5) returns 15
(add10 -7.4) returns 2.6
and
(defun dots (x y / temp)
;(setq temp (strcat x "..."))
;(strcat temp y)
)
(dots "a" "b") returns "a...b"
(dots "from" "to") returns "from...to"
Warning Never use the name of a built-in function or symbol as sym. This makes the built-in function inaccessible. To get a list of built-in and previously defined functions, see "atoms-family."
dictadd: Adds a nongraphical object to the specified dictionary.
(dictadd ename symbol newobj)
Adds the object newobj to the dictionary ename. The symbol argument is the key name of the object to be added to the dictionary, symbol must be a unique name that does not already exist in the dictionary. The object specified by newobj corresponds only to a nongraphical object. As a general rule, each object added to a dictionary must be unique to that dictionary. This is specifically a problem when adding group objects to the group dictionary. Adding the same group object using different key names results in duplicate group names which can send the dictnext function into an infinite loop.
dictnext: Finds the next item in a dictionary.
(dictnext ename [rewind])
The ename argument is an entity name that specifies a dictionary object to search. When dictnext is used repeatedly, it returns the next entry in the specified dictionary each time. The dictsearch function specifies an entry to retrieve. If the rewind argument is present and evaluates to a non-nil value, the dictionary is rewound and the first entry in it is retrieved. When there are no more entries in the dictionary, nil is returned. Deleted dictionary entries are never returned. See "namedobjdict" for the master dictionary entity name. Once you have begun stepping through the contents of a dictionary, passing a different dictionary name to dictnext will cause the place to be lost in the original dictionary. In other words, only one global iterator is maintained for use in this function. If an entry is found, it is returned as a list of dotted pairs of DXF-type codes and values.
dictremove: Removes an entry from the specified dictionary.
(dictremove ename symbol)
Removes the dictionary entry specified by symbol from the dictionary specified by ename. If ename is invalid or symbol is not found, dictremove returns nil. If successful, dictremove returns the entity name of the removed entry. By default, removing an entry from a dictionary does not delete it from the database. This must be done with a call to entdel. Currently the exceptions to this rule are groups and mlinestyles. The code that implements these features requires that the database and these dictionaries be up to date, and therefore automatically deletes the entity when it is removed (with dictremove) from the dictionary. The dictremove function disallows the removal of an mlinestyle from the mlinestyle dictionary if it is actively referenced by an mline in the database.
dictrename: Renames a dictionary entry.
(dictrename ename oldsym newsym)
Renames a dictionary entry's key name from oldsym to newsym. The dictionary is specified by ename. If the oldname is not present in the dictionary, ename is invalid, newname is invalid, or newname is already present in the dictionary. dictrename returns nil.
dictsearch: Searches a dictionary for an item.
(dictsearch ename symbol [setnext])
The ename argument is an entity name that specifies a dictionary object to search. The symbol argument is a string that specifies the item within the dictionary. If dictsearch finds an entry for the given item, it returns that entry in the format described for dictnext. If no such entry is found, it returns nil. Normally, dictsearch has no effect on the order of entries retrieved by dictnext. However, if dictsearch is successful and the setnext argument is present and non-nil, the dictnext entry counter is adjusted so that the following dictnext call returns the entry after the one returned by this dictsearch call. The following example uses dictsearch to retrieve the definition list of the G2 group (this code assumes that a group named G2 exists in the current drawing).
(setq grp (dictsearch (namedobjdict) "ACAD_GROUP"))
(setq g2 (dictsearch (cdr (assoc -1 grp)) "G2"))
(See "namedobjdict" for the master entity name.)
dimx_tile and dimy_tile: Retrieves the dimensions of a tile in dialog box units (dimx_tile key) and ( dimy_tile key)
The dimx_tile function returns the width of the tile, and dimy_tile returns its height. For both functions, the key argument is a string that specifies the tile. The key argument is case sensitive. The coordinates returned are the maximum allowed within the tile, because coordinates are zero based, these functions return one less than the total X or Y dimension (X-1 and Y-1). The dimx_tile and dimy_tile functions are provided for use with vector_image, fill_image, and slide_image, which require you to specify absolute tile coordinates.
distance: Returns the 3D distance between two points.
(distance pt1 pt2)
(distance '(1.0 2.5 3.0) '(7.7 2.5 3.0)) returns 6.7
(distance '(1.0 2.0 0.5) '(3.0 4.0 0.5)) returns 2.82843
If one or both of the supplied points is a 2D point, then distance ignores the Z coordinates of any 3D points supplied and returns the 2D distance between the points as projected into the current construction plane. (See also "Geometric Utilities")
distof: Converts a string that represents a real (floating-point) value into a real value.
(distof string [mode])
The mode argument specifies the units in which the string is formatted. The value should correspond to values allowed for the AutoCAD system variable LUNITS, as shown in the following table. If mode is omitted, distof uses the current value of LUNITS.
Linear units values
Mode value;String format
1 : Scientific
2 : Decimal
3 : Engineering (feet and decimal inches)
4 : Architectural (feet and fractional inches)
5 : Fractional
The argument string must be a string that distof can parse correctly to the mode specified by mode. It can be in the same form that rtos returns, or in a form that AutoCAD allows for keyboard entry. The distof and rtos functions are complementary. If you pass distof a string created by rtos, distof is guaranteed to return a valid value, and vice versa (assuming the mode values are the same). The distof function treats modes 3 and 4 the same. That is, if mode specifies 3 (engineering) or 4 (architectural) units, and string is in either of these formats, distof returns the correct real value. If distof succeeds, it returns a real number, otherwise it returns nil.
done_dialog: Terminates a dialog box.
(done_dialog [status])
You must call done_dialog from within an action expression or callback function (see "action_tile"). If you specify the optional status argument, it must be a positive integer, which start_dialog will return instead of returning 1 for OK or 0 for Cancel. The meaning of any status value greater than 1 depends on your application. The done_dialog function returns a two-dimensional point list that is the (X,Y) location of the dialog box when the user exited it. You can pass this point to a subsequent new_dialog call to reopen the dialog box in the user-selected location.
Note If you provide a callback for the button whose key is "accept" or "cancel" (usually the OK and Cancel buttons), the callback must call done_dialog explicitly. If it doesn't, the user can be trapped in the dialog box. If you don't provide an explicit callback for these buttons and use the standard exit buttons, AutoCAD handles them automatically. Also, an explicit AutoLISP action for the "accept" button must specify a status of 1 (or an application-defined value); otherwise, start_dialog returns the default value, 0, which makes it appear as if the dialog box was canceled.

E   end_image     end_list     entdel     entget     entlast     entmake     entmakex     entmod     entnext     entsel     entupd     eq     equal     error     eval     exit     exp     expand     expt  
end_image: Ends creation of the currently active dialog box image.
(end_image)
This function is the complement of start_image.
end_list: Ends processing of the currently active dialog box list.
(end_list)
This function is the complement of start_list.
entdel: Deletes objects (entities) or undeletes previously deleted objects.
(entdel ename)
The entity specified by ename is deleted if it is currently in the drawing. The entdel function undeletes the entity (restores it to the drawing) if it has been deleted previously in this editing session. Deleted entities are purged from the drawing when the drawing is exited. The entdel function can delete both graphical and non-graphical entities.
(setq e1 (entnext)): ;Sets e1 to the name of the first
;;;entity in the drawing
(entdel e1): ;Deletes entity e1
(entdel e1): ;Undeletes (restores) deleted entity e1
The entdel function operates only on main entities. Attributes and polyline vertices cannot be deleted independently of their parent entities. You can use the command function to operate the ATTEDIT or PEDIT commands to achieve modify subentities. You cannot delete entities within a block definition. However, you can completely redefine a block definition, minus the entity you want deleted, with entmake.
entget: Retrieves an object's (entity's) definition data.
(entget ename [applist])
The entget function returns a list containing the entity definition data of the entity ename. This applies to both graphical and nongraphical entities. If you supply applist, an optional list of registered application names, entget also returns the extended data associated with the specified applications. The data returned by entget is coded as an association list, from which you can extract items by using the assoc function. Objects in the list are assigned AutoCAD DXF group codes for each part of the entity data. Assume that the last object created in the drawing is a line drawn from point (1,2) to point (6,5). You can retrieve the entity name of the last object with the entlast function, and pass that name to entget.
(entget (entlast))
This might return the following:
((-1 . ) Entity name
(0 . "LINE"): Object type
(8 . "0"): Layer
(10 1.0 2.0 0.0): Start point
(11 6.0 6.0 0.0): Endpoint
)
The DXF group codes used by AutoLISP differ slightly from the group codes in a DXF file. As with DXF, entity header items (color, linetype, thickness, the attributes-follow flag, and the entity handle) are exported only if they have nondefault values. Unlike DXF, optional entity definition fields are exported whether they are equal to their defaults or not. This simplifies processing. Programs can always assume these fields to be present for general algorithms that operate on them. Also unlike DXF, associated X, Y, and Z coordinates are grouped together into one point list, as in (10 1.0 2.0 3.0), rather than appearing as separate 10, 20, and 30 groups. The -1 item at the start of the list contains the entity name of this entity. The individual dotted pairs that represent the values can be extracted by assoc, using cdr to pull out their values. The sublists for points are not dotted pairs like the rest. The convention is that the cdr of the sublist is the group's value. Because a point is a list of two (or three) reals, the entire group is a three- (or four-) element list. The cdr of the group is the list representing the point, so the convention that cdr always returns the value is preserved.
When writing functions to process these entity lists, be sure to make them insensitive to the order of the sublists. Use assoc to guarantee this. The -1 group containing the entity's name allows modification operations to accept the entity list, and avoids the need to keep the entity name in a parallel structure. A seqend entity at the end of a polyline or a set of attributes contains a -2 group whose cdr is the entity name of the header of this entity. This allows the header to be found from a subentity by walking forward to the Seqend and then using the cdr of the -2 group as the entity name to retrieve the associated main entity.
Warning: Before performing an entget on vertex entities, you should read or write the polyline entity's header. If the most recently processed polyline entity is different from the one to which the vertex belongs, width information (the 40 and 41 groups) can be lost. All points associated with an object are expressed in terms of that object's Object Coordinate System (OCS). For point, line, 3dline, 3dface, 3dpolyline, 3dmesh, and dimension objects, the OCS is equivalent to the WCS (the object points are World points). For all other objects, the OCS can be derived from the WCS and the object's extrusion direction (its 210 group). When working with objects that have been drawn using coordinate systems other than the WCS, you might need to convert the points to the WCS or to the current UCS by using the trans function.
entlast: Returns the name of the last nondeleted main object (entity) in the drawing.
(entlast)
The entlast function is frequently used to obtain the name of a new entity that has just been added with the command function. The entity need not be on the screen or on a thawed layer to be selected.
(setq e1 (entlast)) Sets e1 to the name of the last main entity in the drawing.
(setq e2 (entnext e1)) Sets e2 to nil (or to an attribute or vertex subentity name).
If your application requires the name of the last nondeleted entity (main entity or subentity), define a function such as the following and call it instead of entlast.
(defun lastent (/ a b)
(if (setq a (entlast)) Gets last main entity.
(while (setq b (entnext a)) If subentities follow, loops until there are no more
(setq a b) subentities
)
)
a Returns last main entity
) or subentity
entmake: Creates a new entity (graphical object) in the drawing.
(entmake [elist])
The elist argument must be a list of entity definition data in a format similar to that returned by the entget function. The elist argument must contain all of the information necessary to define the entity. The entmake function can define both graphical and nongraphical entities. If any required definition data is omitted, entmake returns nil and the entity is rejected. If you omit optional definition data (such as the layer), entmake uses the default value. If entmake successfully creates a new entity, it returns the entity's list of definition data. If entmake is unable to create the entity, it returns nil. One method of creating a new entity is by obtaining an entity's definition data with the entget function, modifying it, and then passing the revised data to the entmake function. Before creating a new entity, entmake verifies that a valid layer name, linetype name, and color are supplied. If a new layer name is introduced, entmake automatically creates the new layer. The entmake function also checks for block names, dimension style names, text style names, and shape names if the entity type requires them. The entity type (for example, CIRCLE or LINE) must be the first or second field of the elist. If it is the second field, it can be preceded only by the entity name. This is the format returned by entget. In such cases, it ignores the entity name when the new entity is created. If the elist contains an entity handle, it also is ignored. The following code creates a red circle, centered at (4,4) with a radius of 1. The optional layer and linetype fields have been omitted and therefore assume default values.
(entmake
'((0 . "CIRCLE"): Entity type
(62 . 1): Color
(10 4.0 4.0 0.0): Center point
(40 . 1.0): Radius
)
)
Note Objects created on a frozen layer are not regenerated until the layer is thawed.
Complex Entities: A complex entity (a block definition, a polyline, or a block reference containing attributes) can be created by several entmake calls to define its subentities (attributes or vertices). When entmake sees that a complex entity is being created, it creates a temporary file to gather the definition data. For each entmake, a check is performed to see if the temporary file exists; if so, the new data is appended to the file. When the definition of the complex entity is complete (by appending the appropriate seqend or endblk entity), the supplied data is rechecked and the complex entity is added to the drawing. Completion of a block definition (entmake of an endblk) returns the block's name rather than the entity data list normally returned. Note that you cannot create viewport objects with entmake. If data is received that is invalid for that entity type, the entity is rejected as well as the entire complex entity. A block definition cannot be nested, nor can it reference itself. However, it can contain references to other block definitions. All entities of a complex entity can exist in either model space or paper space, but not both. A group 66 code is honored only for insert objects (meaning attributes follow). For polyline entities, the group 66 code is forced to a value of 1 (meaning vertices follow), and for all other entities it takes a default of 0. The only entity that can follow a polyline entity is a vertex entity.
No portion of a complex entity is displayed on your drawing until its definition is complete. You can cancel the creation of a complex entity by entering entmake with no arguments. This clears the temporary file and returns nil. The block and endblk entities can be used to create a new block definition. Newly created blocks are automatically entered into the symbol table where they can be referenced. Applications can represent polygons with an arbitrarily large number of sides in polyface meshes. However, the AutoCAD entity structure imposes a limit on the number of vertices that a given face entity can specify. You can represent more complex polygons by dividing them into triangular wedges. AutoCAD represents triangular wedges as four-vertex faces where two adjacent vertices have the same value. Their edges should be made invisible to prevent visible artifacts of this subdivision from being drawn. The PFACE command performs this subdivision automatically, but when applications generate polyface meshes directly, the applications must do this themselves. The number of vertices per face is the key parameter in this subdivision process.
The PFACEVMAX system variable provides an application with the number of vertices per face entity. This value is read-only andis set to 4. Warning When entmake creates a block, it can overwrite an existing block. The entmake function does not check for name conflicts in the block definitions table, so before you use it, use the tblsearch function to ensure that the name of the new block is unique. However, using entmake to redefine anonymous blocks, as described in the following section, can be useful. Anonymous Blocks: The block definitions table in a drawing can contain anonymous blocks. Anonymous blocks are created to support hatch patterns and associative dimensioning. They can also be created by entmake for the application's own purposes, usually to contain entities that the user cannot access directly. The group code 2 (block name) of a dimension entity is optional for the entmake function. If the block name is omitted from the entity definition list, AutoCAD creates a new one. Otherwise, AutoCAD creates the dimension using the name provided. The name (group 2) of an anonymous block is *Unnn, where nnn is a number generated by AutoCAD. Also, the low-order bit of an anonymous block's Block type flag (group 70) is set to 1. When entmake creates a block whose name begins with * and whose anonymous bit is set, AutoCAD treats this as an anonymous block and assigns it a name. Characters following the * in the name string passed to entmake are ignored. After the block is created, entmake returns its name. If you are creating the block by multiple entmake calls, it returns the name after a successful call of (entmake "endblk"). Whenever a drawing is opened, all unreferenced anonymous blocks are purged from the block definitions table. Referenced (inserted) anonymous blocks are not purged. You can use entmake to create a block reference (Insert) to an anonymous block (you cannot pass an anonymous block to the INSERT command). You can also use entmake to redefine the block. The entities in a block (but not the block entity itself) can be modified with entmod. Note that although a referenced anonymous block becomes permanent, the numeric portion of its name can change between drawing sessions. Applications cannot rely on anonymous block names remaining constant.
entmakex: Makes a new object or entity, gives it a handle and entity name (but, does not assign an owner), and then returns the new entity name.
(entmakex [elist])
The elist argument must be a list of entity definition data in a format similar to that returned by the entget function. The elist argument must contain all of the information necessary to define the entity or object. The entmakex function can define both graphical and nongraphical objects. If any required definition data is omitted, entmakex returns nil and the object is rejected. If you omit optional definition data (such as the layer), entmakex uses the default values. If entmakex successfully creates a new entity, it returns the entity name. If entmakex is unable to create the entity, it returns nil. Warning Objects and entities without owners are not written out to .dwg or .dxf files. Be sure to set an owner at some point after using entmakex. For example, you can use dictadd to set a dictionary to own an object.
entmod: Modifies the definition data of an object (entity).
(entmod elist)
The entmod function is passed a list (elist) in the format returned by entget, and it updates the database information for the entity name specified by the -1 group in elist. The primary mechanism through which AutoLISP updates the database is by retrieving entities with entget, modifying the list defining an entity, and updating the entity in the database with entmod. The entmod function can modify both graphical and nongraphical objects.
(setq en (entnext)) Sets en to the name of the first entity in the drawing.
(setq ed (entget en)) Sets ed to the entity data of entity en
(setq ed
(subst (cons 8 "0")
(assoc 8 ed) Changes the layer group in ed to layer 0
ed
)
)
(entmod ed) Modifies entity en's layer in drawing.
The entmod function imposes some restrictions on the changes it makes. First of all, an entity's type and handle cannot be changed. If you want to do this, just entdel it and make a new entity with the command or entmake functions. All objects referenced by the entity list must be known to AutoCAD before the entmod is executed. Thus text style, linetype, shape, and block names must be defined in a drawing before they can be used in an entity list with entmod. An exception to this is layer names: entmod creates a new layer with the standard defaults used by the New option of LAYER if a previously undefined layer is named in an entity list.
For entity fields with floating-point values (such as thickness), entmod accepts integer values and converts them to floating point. Similarly, if you supply a floating-point value for an integer entity field (such as color number), entmod truncates it and converts it to an integer. The entmod function performs consistency checking on the list supplied to it. If a serious error is detected, the database is not updated and nil is returned. Otherwise, entmod returns the list given to it as its argument. entmod cannot change internal fields such as the entity name in the -2 group of a seqend entity--attempts to change such fields are ignored. When entmod updates a main entity, it modifies the entity and updates its image on screen (including subentities). When entmod updates a subentity (a polyline vertex or a block attribute), the subentity is updated in the database but the image on the screen is not redisplayed. After all modifications are made to a given entity's subentities, the entupd function can be used to update the image on the screen.
Note You cannot use the entmod function to modify a viewport entity. You can change an entity's space visibility field to 0 or 1 (except for viewport objects). If you use entmod to modify an entity within a block definition, the modification affects all instances of the block in the drawing. Before performing an entmod on vertex entities, you should read or write the polyline entity's header. If the most recently processed polyline entity is different from the one to which the vertex belongs, width information (the 40 and 41 groups) can be lost. Warning: You can use entmod to modify entities within a block definition, but doing so can create a selfreferencing block, which will cause AutoCAD to stop.
entnext: Returns the name of the next object (entity) in the drawing.
(entnext [ename])
If entnext is called with no arguments, it returns the entity name of the first nondeleted entity in the database. If entnext is called with an entity name argument ename, it returns the entity name of the first nondeleted entity following ename in the database. If there is no next entity in the database, it returns nil. The entnext function returns both main entities and subentities. The entities selected by ssget are main entities, not attributes of blocks or vertices of polylines. You can access the internal structure of these complex entities by walking through the subentities with entnext. Once you obtain a subentity's name, you can operate on it like any other entity. If you obtain the name of a subentity with entnext, you can find the parent entity by walking forward with entnext until a seqend entity is found, then extracting the -2 group from that entity, which is the main entity's name.
(setq e1 (entnext)) Sets e1 to the name of the first entity in the drawing
(setq e2 (entnext e1)) Sets e2 to the name of the entity following e1.
entsel: Prompts the user to select a single object (entity) by specifying a point.
(entsel [msg])
The entsel function returns a list whose first element is the entity name of the chosen object and whose second element is the coordinates (in terms of the current UCS) of the point used to pick the object. If a string is specified for msg, that string is used to ask the user for the object. Otherwise, the prompt defaults to Select object. Note that the pick point returned by entsel does not represent a point that lies on the selected object. The point returned is the location of the crosshairs at the time of selection. The relationship between the pick point and the object will vary depending on the size of the pickbox and the current zoom scale. A list of the form returned by entsel can be supplied to AutoCAD in response to any of its object selection prompts. It is treated byAutoCAD as a pick of the designated object by pointing to the specified point. The following AutoCAD command sequence illustrates the use of the entsel function and the list returned:
Command: line
From point: 1,1
To point: 6,6
To point: ENTER
Command: (setq e (entsel "Please choose an object: "))
Please choose an object: 3,3
( (3.0 3.0 0.0))
Sometimes when operating on objects, you will want to simultaneously select an object and specify the point by which it was selected. Examples of this in AutoCAD can be found in Object Snap and in the BREAK, TRIM, and EXTEND commands. The entsel function allows AutoLISP programs to perform this operation. It selects a single object, requiring the selection to be by a point pick. The current Osnap setting is ignored by this function (no object snap) unless you specifically request it while you are in the function. The entsel function honors key words from a preceding call to initget.
entupd: Updates the screen image of an object (entity)
(entupd ename)
When a polyline vertex or block attribute is modified with entmod, the entire complex entity is not updated on the screen. The entupd function can be used to cause a modified polyline or block to be updated on the screen. This function can be called with the entity name of any part of the polyline or block; it need not be the head entity. While entupd is intended for polylines and blocks with attributes, it can be called for any entity. It always regenerates the entity on the screen, including all subentities. Note that if entupd is used on a nested entity (an entity within a block) or on a block that contains nested entities, some of the entities might not be regenerated. To ensure complete regeneration, you must invoke the REGEN command.
Assuming that the first entity in the drawing is a polyline with several vertices, then
(setq e1 (entnext)): Sets e1 to the polyline's entity name
(setq e2 (entnext e1)): Sets e2 to its first vertex
(setq ed (entget e2)): Sets ed to the vertex data
(setq ed
(subst '(10 1.0 2.0)
(assoc 10 ed): Changes the vertex's location in ed
ed: to point (1,2)
)
)
(entmod ed): Moves the vertex in the drawing
(entupd e1): Regenerates the polyline entity e1
eq: Determines whether two expressions are identical.
(eq expr1 expr2)
The eq function determines whether expr1 and expr2 are bound to the same object (by setq, for example). Returns T if the two expressions are identical, and returns nil otherwise. You can use this function to determine whether two lists are the same. For example, given the assignments.
(setq f1 '(a b c))
(setq f2 '(a b c))
(setq f3 f2)
then
(eq f1 f3) returns nil, f1 and f3 are not the same list
(eq f3 f2) returns T, f3 and f2 are exactly the same list
(See also the = (equal to) and equal functions)
equal: Determines whether two expressions are equal.
(equal expr1 expr2 [fuzz])
The equal function determines whether expr1 and expr2 evaluate to the same thing. When comparing two real numbers (or two lists of real numbers, as in points), the two identical numbers can differ slightly if different methods are used to calculate them. Therefore, you can use an optional numeric argument, fuzz, to specify the maximum amount by which expr1 and expr2 can differ and still be considered equal.
For example, given the assignments
(setq f1 '(a b c))
(setq f2 '(a b c))
(setq f3 f2)
(setq a 1.123456)
(setq b 1.123457)
then
(equal f1 f3) returns T
(equal f3 f2) returns T
(equal a b) returns nil
(equal a b 0.000001) returns T
Although two lists that the equal function finds the same might not be found so using the eq function, atoms that are found to be the same using the equal function are always found to be the same if you use the eq function. However, if the eq function finds that the list or atoms are the same, the equal function also finds them to be the same.
(See also the = (equal to)and eq functions)
*error*: A user-definable error-handling function.
(*error* string)
If *error* is not nil, it is executed as a function whenever an AutoLISP error condition exists. AutoCAD passes one argument to *error*, which is a string containing a description of the error. The following function does the same thing that the AutoLISP standard error handler does. Print error and the description.
(defun *error* (msg)
(princ "error: ")
(princ msg)
(princ)
)
Your *error* function can include calls to the command function without arguments (for example, (command)). This will cancel a previous AutoCAD command called with the command function. (See also "Error Handling" for an example of an error handler that tests for the string returned by the exit and quit functions).
eval: Returns the result of evaluating an AutoLISP expression.
(eval expr)
For example, given the assignments
(setq a 123)
(setq b 'a)
then
(eval 4.0): returns 4.0
(eval (abs -10)): returns 10
(eval a): returns 123
(eval b): returns 123
exit: Forces the current application to quit.
(exit)
If exit is called, it returns the error message quit/exit abort and returns to the AutoCAD Command prompt.
(See also the quit function)
exp: Returns the constant e (a real) raised to a specified power (the natural antilog).
(exp num)
(exp 1.0): returns 2.71828
(exp 2.2): returns 9.02501
(exp -0.4): returns 0.67032
expand: Allocates node space by requesting a specified number of segments.
(expand int) (See also "Manual Allocation" for more information on expand)
expt: Returns a number raised to a specified power.
(expt number power)
If both arguments are integers, the result is an integer. Otherwise, the result is a real. These are examples:
(expt 2 4): returns 16
(expt 3.0 2.0): returns 9.0

F   fill_image     findfile     fix     float     foreach  
fill_image: Draws a filled rectangle in the currently active dialog box image tile.
(fill_image x1 y1 wid hgt color)
The fill_image function must be used between start_image and end_image calls. The color parameter is an AutoCAD color number or one of the logical color numbers shown in the following table.
Symbolic names for the color attribute.
Color number : ADI mnemonic : Description
-2 : BGLCOLOR: Current background of the AutoCAD graphics screen
-15 : DBGLCOLOR: Current dialog box background color
-16 : DFGLCOLOR: Current dialog box foreground color (text)
-18 : LINELCOLOR: Current dialog box line color
The first (upper-left) corner of the rectangle is located at (x1, y1) and the second (lower-right) corner is located the relative distance (wid,hgt) from the first corner (wid and hgt must be positive values). The origin (0,0) is the upper-left corner of the image. You can obtain the coordinates of the lower-right corner by calling the dimension functions dimx_tile and dimy_tile.
findfile: Searches the AutoCAD library path for the specified file.
(findfile filename)
The findfile function makes no assumption about the file type or extension of filename. If filename does not specify a drive/directory prefix, findfile searches the AutoCAD library path. If a drive/directory prefix is supplied, findfile looks only in that directory. The findfile function always returns a fully qualified drive/directory/file name or nil if the specified file is not found.
Consider the following examples. If the current directory is /acad and it contains the file abc.lsp. (findfile "abc.lsp") returns "/acad/abc.lsp". If you are editing a drawing in the /acad/drawings directory, the ACAD environment variable is set to /acad/support, and the file xyz.txt exists only in the /acad/support directory.
(findfile "xyz.txt") returns "/acad/support/xyz.txt"
If the file nosuch is not present in any of the directories on the library search path.
(findfile "nosuch") returns nil.
The fully qualified name returned by findfile is suitable for use with the open function.
fix: Returns the conversion of a real into the nearest smaller integer.
(fix num)
The fix function truncates number to the nearest integer by discarding the fractional portion.
(fix 3) returns 3
(fix 3.7) returns 3
Note If number is larger than the largest possible integer (+2,147,483,647 or -2,147,483,648 on a 32-bit platform), fix returns a truncated real (although integers transferred between AutoLISP and AutoCAD are restricted to 16-bit values).
float: Returns the conversion of a number into a real.
(float num)
(float 3) returns 3.0
(float 3.75) returns 3.75
foreach: Evaluates expressions for all members of a list.
(foreach name lst expr...)
Steps through lst, assigning each element to name, and evaluates each expr for every element in the list. Any number of exprs can be specified. The foreach function returns the result of the last expr evaluated.
(foreach n '(a b c) (print n))
is equivalent to
(print a)
(print b)
(print c) and returns c
except that foreach returns the result of only the last expression evaluated.

G   gc     gcd     get_attr     get_tile     getangle     getcfg     getcname     getcorner     getdist     getenv     getfiled     getint     getkword     getorient     getpoint     getreal     getstring     getvar     graphscr     grclear     grdraw     grread     grtext     grvecs  
gc: Forces a garbage collection, which frees up unused nodes.
(gc)
(See also "Node Space" for a more detailed explanation of garbage collection)
gcd: Returns the greatest common denominator of two integers. (gcd int1 int2)
The int1 and int2 arguments must be integers greater than 0.
(gcd 81 57) returns 3
(gcd 12 20) returns 4
get_attr: Retrieves the DCL value of a dialog box attribute.
(get_attr key attribute)
The key argument is a string that specifies the tile and is case sensitive. The attribute argument specifies the name of the attribute as it appears in the tile's DCL description. Both the key and attribute arguments are strings. The value returned is the attribute's initial value as specified in its DCL description; it does not reflect changes to the state of the tile that come about with user input or set_tile calls. Returns the attribute value as a string.
get_tile: Retrieves the current run-time value of a dialog box tile.
(get_tile key)
The key argument is a string that specifies the tile and is case sensitive. It returns the tile's value as a string.
getangle: Pauses for user input of an angle, and returns that angle in radians.
(getangle [pt] [msg])
The pt argument is a 2D base point in the current UCS, and msg is a string to be displayed as a prompt. The pt argument, if specified, is assumed to be the first of two points, so that the user can show AutoLISP the angle by pointing to one other point. You can supply a 3D base point, but the angle is always measured in the current construction plane. The getangle function measures angles with the zero-radian direction (set by the ANGBASE system variable) with angles increasing in the counterclockwise direction. The returned angle is expressed in radians with respect to the current construction plane (the XY plane of the current UCS, at the current elevation). The user can specify an angle by entering a number in the AutoCAD current angle units format.
Although the current angle units format might be in degrees, grads, or some other unit, this function always returns the angle in radians. The user can also show AutoLISP the angle by pointing to two 2D locations on the graphics screen. AutoCAD draws a rubber-band line from the first point to the current crosshair position to help you visualize the angle. It is important to understand the difference between the input angle and the angle returned by getangle. Angles that are passed to getangle are based on the current settings of ANGDIR and ANGBASE. However, once an angle is provided, it is measured in a counterclockwise direction (ignoring ANGDIR) with zero radians as the current setting of ANGBASE. The following code examples show how different arguments can be used.
(setq ang (getangle))
(setq ang (getangle '(1.0 3.5)))
(setq ang (getangle "Which way? "))
(setq ang (getangle '(1.0 3.5) "Which way? "))
The user cannot enter another AutoLISP expression as the response to a getangle request. (See also the illustration and comparison to the getorient function)
getcfg: Retrieves application data from the AppData section of the acad.cfg file.
(getcfg cfgname)
The cfgname argument is a string (maximum length of 347 characters) naming the section and parameter value to retrieve. If cfgname is not valid, getcfg returns nil. The cfgname argument must be a string of this form: "AppData/application_name/section_name/.../param_name"
For example, assuming that the WallThk parameter in the AppData/ArchStuff section has a value of 8, (getcfg "AppData/ArchStuff/WallThk") returns "8". (See also the setcfg function)
getcname: Retrieves the localized or English name of an AutoCAD command.
(getcname cname)
The cname argument specifies the localized or underscored English command name, which must be 64 characters or less in length. If cname is not preceded by an underscore (assumed to be the localized command name), getcname returns the underscored English command name. If cname is preceded by an underscore, getcname returns the localized command name. This function returns nil if cname is not a valid command name. For example, in a French version of AutoCAD, the following is true.
(getcname "ETIRER") returns "_STRETCH"
(getcname "_STRETCH") returns "ETIRER"
getcorner: Pauses for user input of a rectangle's second corner.
(getcorner pt [msg])
The getcorner function requires a base point argument, pt, based on the current UCS, and draws a rectangle from that point as the user moves the crosshairs on the screen. The msg argument is a string to be displayed as a prompt. The getcorner function returns a point in the current UCS, similar to getpoint. If the user supplies a 3D point, its Z coordinate is ignored. The current elevation is used as the Z coordinate. The user cannot enter another AutoLISP expression as the response to a getcorner request.
getdist: Pauses for user input of a distance.
(getdist [pt] [msg])
The pt argument is a 2D or 3D base point in the current UCS. If provided, pt is used as the first of the two points and the user is prompted for only the second point. The msg argument is a string to be displayed as a prompt. The user can specify the distance by selecting two points, or the second point if a base point is provided. The user can also specify a distance by entering a number in the AutoCAD current distance units format. Although the current distance units format might be in feet and inches (architectural), the getdist function always returns the distance as a real. The getdist function draws a rubber-band line from the first point to the current crosshair position to help the user visualize the distance. If a 3D point is provided, the returned value is a 3D distance.
However, setting the 64 bit of the initget function instructs getdist to ignore the Z component of 3D points and to return a 2D distance.
(setq dist (getdist))
(setq dist (getdist '(1.0 3.5)))
(setq dist (getdist "How far "))
(setq dist (getdist '(1.0 3.5) "How far? "))
The user cannot enter another AutoLISP expression as the response to a getdist request.
getenv: Returns the string value assigned to a system environment variable.
(getenv variable-name)
The variable-name argument is a string specifying the name of the variable to be read. If this variable does not exist, getenv returns nil. For example, if the system environment variable ACAD is set to /acad/support and there is no variable named NOSUCH, then (getenv "ACAD") returns "/acad/support" (getenv "NOSUCH") returns nil.
Note: On UNIX systems, ACAD and acad refer to two separate environment variables, because these operating systems are case sensitive.
getfiled: Prompts the user for a file name with the standard AutoCAD file dialog box, and returns that file name.
(getfiled title default ext flags)
The title argument specifies the dialog box label, default specifies a default file name to use (which can be a null string [""]), and ext is the default file name extension. If ext is passed as a null string [""], it defaults to * (all file types). If the file type dwg is included in the ext argument, the getfiled function displays an image preview in the dialog. The flags argument is an integer value (a bit-coded field) that controls the behavior of the dialog box. To set more than one condition at a time, add the values together to create a flags value between 0 and 15.
Flag value = 1 (bit 0)
Set this bit when you prompt for the name of a new file to create. Do not set this bit when you prompt for the name of an existing file to open. In the latter case, if the user enters the name of a file that doesn't exist, the dialog box displays an error message at the bottom of the box. If this bit is set and the user chooses a file that already exists, AutoCAD displays an alert box and offers the choice of proceeding with or canceling the operation.
Flag value = 2 (bit 1)
Disables the Type it button. This bit is set if getfiled is called while another dialog box is active. (Otherwise it forces the other dialog box to disappear.) If this bit is not set, the Type it button is enabled. If the user selects the button, the dialog box disappears and getfiled returns a value of 1.
Flag value = 4 (bit 2)
Lets the user enter an arbitrary file name extension, or no extension at all. If this bit is not set, getfiled accepts only the extension specified in the ext argument and appends this extension to the file name if the user doesn't enter it in the File text box.
Flag value = 8 (bit 3)
If this bit is set and bit 0 is not set, getfiled performs a library search for the file name entered. If it finds the file and its directory in the library search path, it strips the path and returns only the file name. (It doesn't strip the path name if it finds that a file of the same name is in a different directory.) If this bit is not set, getfiled returns the entire file name, including the path name. Set this bit if you use the dialog box to open an existing file whose name you want to save in the drawing (or other database). If the dialog box obtains a file name from the user, getfiled returns a string that specifies the file name; otherwise, it returns nil. The following call to getfiled displays the Select a Lisp File dialog box:
(getfiled "Select a Lisp File" "/acadr14/support/" "lsp" 8)
The getfiled function displays a dialog box containing a list of available files of a specified extension type. You can use this dialog box to browse through different drives and directories, select an existing file, or specify the name of a new file.
getint: Pauses for user input of an integer, and returns that integer.
(getint [msg])
The msg argument is an optional string to be displayed as a prompt. The getint function returns the integer value or nil.
(setq num (getint))
(setq num (getint "Enter a number: "))
Values passed to getint can range from -32,768 to +32,767. The user cannot enter another AutoLISP expression as the response to a getint request. (See also "The getxxx Functions" and the if function)
getkword: Pauses for user input of a key word, and returns that key word.
(getkword [msg])
Valid key words are set prior to the getkword call with the initget function. The msg argument is a string to be displayed as a prompt. The getkword function returns the key word matching the user input as a string. AutoCAD tries again if the input is not a key word. If the input is null (ENTER), getkword returns nil (if null input is allowed). This function also returns nil if it wasn't preceded by a call to initget that established one or more key words. The following example shows an initial call to initget that sets up a list of key words (Yes and No) and disallows null input (bits value equal to 1) to the following getkword call:
(initget 1 "Yes No")
(setq x (getkword "Are you sure? (Yes or No) "))
This code prompts the user for input and sets the symbol x to either Yes or No, depending on the response. If the response does not match any of the key words, or if the user gives a null reply, AutoCAD prompts again with the string supplied in the msg argument.
If no msg argument is provided, AutoCAD supplies this prompt:
Try again:
The user cannot enter another AutoLISP expression as the response to a getkword request.
(See also "The getxxx Functions" and the if function)
getorient: Pauses for user input of an angle, and returns that angle in radians.
(getorient [pt] [msg])
This function is similar to the getangle function, except that the angle value returned by getorient is unaffected by the system variables ANGBASE and ANGDIR. However, the angle input by the user is still based on the current settings of ANGDIR and ANGBASE. The pt argument is a 2D base point in the current UCS, and msg is a string to be displayed as a prompt. The pt argument, if specified, is assumed to be the first of two points, allowing the user to show AutoLISP the angle by pointing to one other point. You can supply a 3D base point, but the angle is always measured in the current construction plane. The getorient function measures angles with the zero-radian direction to the right (east) and angles that are increasing in the counterclockwise direction. As with getangle, getorient expresses the returned angle in radians, with respect to the current construction plane. Angles input to getorient are based on the current settings of ANGDIR and ANGBASE. However, once an angle is provided, it is measured in a counterclockwise direction, with zero radians being to the right (ignoring ANGDIR and ANGBASE). Therefore, some conversion must take place if you select a different zero-degree base or a different direction for increasing angles by using the UNITS command or the ANGBASE and ANGDIR system variables. Use getangle when you need a rotation amount (a relative angle). Use getorient to obtain an orientation (an absolute angle). The user cannot enter another AutoLISP expression as the response to a getorient request. (See also "The getxxx Functions" and the getangle and if functions).
getpoint: Pauses for user input of a point, and returns that point.
(getpoint [pt] [msg])
The pt argument is a 2D or 3D base point in the current UCS, and msg is a string to be displayed as a prompt. The user can specify a point by pointing or by entering a coordinate in the current units format. If the pt argument is present, AutoCAD draws a rubberband line from that point to the current crosshair position. The returned value is a 3D point expressed in terms of the current UCS.
(setq p (getpoint))
(setq p (getpoint "Where? "))
(setq p (getpoint '(1.5 2.0) "Second point: "))
The user cannot enter another AutoLISP expression as the response to a getpoint request. (See also "The getxxx Functions" and the getcorner and if functions)
getreal: Pauses for user input of a real number, and returns that real number.
(getreal [msg])
The msg argument is a string to be displayed as a prompt.
(setq val (getreal))
(setq val (getreal "Scale factor: "))
The user cannot enter another AutoLISP expression as the response to a getreal request.
getstring: Pauses for user input of a string, and returns that string.
(getstring [cr] [msg])
If the cr argument is supplied and is not nil, the input string can contain blanks (and must be terminated by a ENTER). Otherwise, the input string is terminated by space or ENTER. The msg argument is a string to be displayed as a prompt. If the string is longer than 132 characters, it returns only the first 132 characters of the string. If the input string contains the backslash character (\), it is converted to two backslash characters (\\). This is done so that the returned value can contain file name paths that can be used by other functions.
(setq s (getstring "What's your first name? "))
responding John sets s to "John"
(setq s (getstring T "What's your full name? "))
responding John Doe sets s to "John Doe"
(setq s (getstring "Enter filename: "))
responding \acad\mydwg sets s to "\\acad\\mydwg"
The user cannot enter another AutoLISP expression as the response to a getstring request. (See also the getkword function for a routine that requires the user to enter one of several known options (key words))
getvar: Retrieves the value of an AutoCAD system variable.
(getvar varname)
The varname argument is a string that names the system variable. If varname is not a valid system variable, getvar returns nil.
For example, assuming that the fillet radius is set to 0.25 units, (getvar "FILLETRAD") returns 0.25.
You can find a list of the current AutoCAD system variables in the Command Reference. (See also the setvar function)
graphscr: Displays the AutoCAD graphics screen.
(graphscr)
The graphscr function always returns nil.
This function is equivalent to the GRAPHSCR command or to pressing the Flip Screen function key. The textscr function is the complement of graphscr.
grclear: Obsolete function (Previously cleared the current viewport)
(grclear)
To preserve limited compatibility with previous releases, the grclear function returns nil.
grdraw: Draws a vector between two points, in the current viewport.
(grdraw from to color [highlight])
The from and to arguments are 2D or 3D points (lists of two or three reals) that specify the endpoints of the vector in terms of the current UCS. AutoCAD clips the vector to fit the screen. The grdraw function draws the vector with the color specified by the integer color argument, with -1 signifying XOR ink, which complements anything it draws over and which erases itself when overdrawn. If the integer highlight argument supplied is nonzero, the vector is drawn using the default highlighting method of the display device (usually dashed). If highlight is omitted or is zero, grdraw uses the normal display mode. This function always returns nil. (See also the grvecs function for a routine that draws multiple vectors)
grread: Reads values from any of the AutoCAD input devices.
(grread [track] [allkeys [curtype]])
Only specialized AutoLISP routines need this function. Most input to AutoLISP should be obtained through the various getxxx functions. If the track argument is supplied and is not nil, it enables the return of coordinates from a pointing device as it is moved. If the allkeys argument is present, grread performs functions depending on the code supplied. The curtype argument can be used to control the type of cursor displayed. The allkeys and curtype arguments are both integers and are explained as follows: allkeys: The allkeys bit code values can be added together for combined functionality.
1 (bit 0) Return drag mode coordinates. If this bit is set and the user moves the pointing device instead of selecting a button or pressing a key, grread returns a list where the first member is a type 5 and the second member is the (X,Y) coordinates of the current pointing device (mouse or digitizer) location. This is how AutoCAD implements dragging.
2 (bit 1) Return all key values, including function and cursor key codes, and don't move the cursor when the user presses a cursor key.
4 (bit 2) Use the value passed in the curtype argument to control the cursor display.
8 (bit 3) Don't display the error: console break message when the user presses CTRL+C.
curtype: The allkeys value for bit 2 must be set for the curtype values to take effect.
0 Display the normal crosshairs.
1 Do not display a cursor (no crosshairs).
2 Display the object-selection "target" cursor.
Note that the curtype argument affects only the cursor type during the current grread function call.
Note Additional control bits might be defined in future AutoCAD releases. The grread function returns a list whose first element is a code specifying the type of input. The second element of the list is either an integer or a point, depending on the type of input. The return values are listed in the following table.
grread return values
First element, Second element
Value : Type of input : Value : Description
2 : Keyboard input : varies : Character code
3 : Selected point : 3D point : Point coordinates
4 : Screen/pull-down menu item (from pointing device) : 0 to 999, 1001 to 1999, 2001 to 2999, 3001 to 3999
... and so, to
16001 to 16999 : Screen menu box no.
POP1 menu box no.
POP2 menu box no.
POP3 menu box no.
...
POP16 menu box no.
5 : Pointing device (returned only if tracking is enabled) : 3D point : Drag mode coordinate.
6 : BUTTONS menu item : 0 to 999, 1000 to 1999, 2000 to 2999, 3000 to 3999
BUTTONS1 menu button no.
BUTTONS2 menu button no.
BUTTONS3 menu button no.
BUTTONS4 menu button no.
7 : TABLET1 menu item : 0 to 32767 : Digitized box no.
8 : TABLET2 menu item : 0 to 32767 : Digitized box no.
9 : TABLET3 menu item : 0 to 32767 : Digitized box no.
10 : TABLET4 menu item : 0 to 32767 : Digitized box no.
11 : AUX menu item : 0 to 999
1000 to 1999
2000 to 2999
3000 to 3999
AUX1 menu button no.
AUX2 menu button no.
AUX3 menu button no.
AUX4 menu button no.
12 : Pointer button (follows a type 6 or type 11 return) : 3D point : Point coordinates
Entering ESC while a grread is active aborts the AutoLISP program with a keyboard break (unless the allkeys argument has disallowed this). Any other input is passed directly to grread, giving the application complete control over the input devices. If the user presses the pointer button within a screen menu or pull-down menu box, grread returns a type 6 or type 11 code, but in a subsequent call, it does not return a type 12 code: the type 12 code follows type 6 or type 11 only when the pointer button is pressed while it is in the graphics area of the screen. It is important to clear the code 12 data from the buffer before attempting another operation with a pointer button or with an auxiliary button. To accomplish this, perform a nested grread like this:
(setq code_12 (grread (setq code (grread))))
This sequence captures the value of the code 12 list as streaming input from the device. Note that because input is handled differently on the various platforms supported by AutoCAD, the grread function may return unexpected results. The default pointing device on platforms that use a system mouse returns a code 11, not a code 6. On the Macintosh platform, the pop menus return a code 11, not a code 4. Also on the Macintosh, a double-click returns a code 11 (not a code 6) and is followed by a code 5 coordinate pair if selected in the current viewport. Conversely, a double-click in a viewport other than the current one returns a code 3 coordinate pair followed by a code 11.
grtext: Writes text to the status line or to screen menu areas.
(grtext [box text [highlight]])
The box argument is an integer that specifies the location in which to write the text. The text argument is a string that specifies the text to be written to the screen menu or status line location. The text argument is truncated if it is too long to fit in the available area. The highlight argument is an integer that selects or deselects a screen menu location. The values for these arguments vary depending on the screen location to which you are writing. This function displays the supplied text in the menu area; it does not change the underlying menu item. The grtext function can be called with no arguments to restore all text areas to their standard values. If successful, the > # end of Markergrtext function returns the string passed in the text argument, and returns nil if unsuccessful.
Screen Menu Area: Setting box to a positive or zero value specifies a screen menu location. Valid box values range from 0 to the highest-numbered screen menu box minus 1. The SCREENBOXES system variable reports the maximum number of screen menu boxes. If the highlight argument is supplied as a positive integer, grtext highlights the text in the designated box. Highlighting a box automatically dehighlights any other box already highlighted. If highlight is zero, the menu item is dehighlighted. If highlight is a negative number, it is ignored. On some platforms, the text must first be written without the highlight argument and then must be highlighted. Highlighting of a screen menu location works only when the cursor is not in that area.
Status Line Area: If grtext is called with a box value of -1, it writes the text into the mode status line area. The length of the mode status line differs from display to display (most allow at least 40 characters). The following code uses the $(linelen) DIESEL expression to report the length of the mode status area.
(setq modelen (menucmd "M=$(linelen)"))
If a box value of -2 is used, grtext writes the text into the coordinate status line area. If coordinate tracking is turned on, values written into this field are overwritten as soon as the pointer sends another set of coordinates. For both -1 or -2 box values, the highlight argument is ignored.
grvecs: Draws multiple vectors on the graphics screen.
(grvecs vlist [trans])
The vlist argument is a vector list comprised of a series of optional color integers and two point lists. The trans argument is a transformation matrix that you can use to change the location or proportion of the vectors defined in your vector list. This matrix is a list of four lists of four real numbers. The format for vlist is as follows:
([color1] from1 to1 [color2] from2 to2 ...)
The color value applies to all succeeding vectors until vlist specifies another color. AutoCAD colors are in the range 0-255. If the color value is greater than 255, succeeding vectors are drawn in XOR ink, which complements anything it draws over and which erases itself when overdrawn. If the color value is less than zero, the vector is highlighted. Highlighting depends on the display device. Most display drivers indicate highlighting by a dashed line, but some indicate it by using a distinctive color. A pair of point lists, from and to, specify the endpoints of the vectors, expressed in the current UCS. These can be two-dimensional or threedimensional points. You must pass these points as pairs--two successive point lists--or the grvecs call will fail. AutoCAD clips the vectors as required to fit on the screen. If the call to grvecs is successful, it returns nil. The following code draws five vertical lines on the graphics screen, each a different color:
(grvecs '(1 (1 2)(1 5) Draws a red line from (1,2) to (1,5)
; 2 (2 2)(2 5) Draws a yellow line from (2,2) to (2,5)
3 (3 2)(3 5) Draws a green line from (3,2) to (3,5)
4 (4 2)(4 5) Draws a cyan line from (4,2) to (4,5)
5 (5 2)(5 5) Draws a blue line from (5,2) to (5,5)
) )
The following matrix represents a uniform scale of 1.0 and a translation of 5.0,5.0,0.0. If this matrix is applied to the preceding list of vectors, they will be offset by 5.0,5.0,0.0.
'((1.0 0.0 0.0 5.0)
(0.0 1.0 0.0 5.0)
(0.0 0.0 1.0 0.0)
(0.0 0.0 0.0 1.0)
)
(See also the nentselp function for more information on transformation matrixes)

H   handent     help  
handent: Returns an object (entity) name based on its handle.
(handent handle)
Given an entity handle string as the handle argument, the handent function returns the entity name associated with that handle in the current editing session. The handent function returns the entity name of both graphic and nongraphic entities. If handent is passed an invalid handle or a handle not used by any entity in the current drawing, nil is returned. The handent function returns entities that have been deleted during the current editing session. You can undelete them with the entdel function. An entity's name can change from one editing session to the next, but an entity's handle remains constant. In a particular editing session, the code
(handent "5A2") might return
Used with the same drawing but in another editing session, the same call might return a different entity name. Once the entity name is obtained, it can be used to manipulate the entity with any of the entity-related functions.
help: Invokes the help facility.
(help [helpfile [topic [command]]])
The helpfile argument is a string that specifies a help file. If you specify an AutoCAD Help file (.ahp), the help function uses the AutoCAD Help viewer to display the contents of that file. If you specify a Windows Help file (.hlp) the help function uses the WinHelp program to display the file. If the helpfile argument is an empty string ("") or is omitted, AutoCAD uses the default AutoCAD Help file. The topic argument is a key word that specifies the topic initially displayed by the help facility. If the topic argument is an empty string (""), the help facility displays the introductory part of the help file. The command argument is a string that specifies the initial state of the Help window, as described in the following table.
Values for the command argument
String : Description
HELP_CONTENTS : Displays the first topic in the Help file
HELP_HELPONHELP : Displays help on using help
HELP_PARTIALKEY : Displays the Search dialog using the string passed as the topic as the initial search text
If you are specifying a Windows Help file, the command argument can also be a string used by the fuCommand argument of the WinHelp() function as defined by the WinHelp API in the Microsoft Windows SDK. The file extension is not required with the helpfile argument. If a file extension is provided, AutoCAD looks only for that file. If no file extension is provided, the following search rules apply: append .hlp, else append .ahp. The only error condition that the help function returns to the application is the existence of the file specified by helpfile. All other error conditions are reported to the user through a dialog box. The help function returns the helpfile string if it succeeds and nil if it fails. If you use help without any arguments, it returns an empty string ("") if successful, and nil if it fails. The following code calls help to display the information on MYCOMMAND in the help file.
achelp.ahp:
(help "achelp.ahp" "mycommand")
(See also "Custom Online Documentation" for information on creating AutoCAD Help files. The setfunhelp function associates context-sensitive help (when the user presses F1) with a user-defined command.)

I   if     initget     inters     itoa  
if: Conditionally evaluates expressions.
(if testexpr thenexpr [elseexpr])
If testexpr is not nil, it evaluates thenexpr; otherwise it evaluates elseexpr. The if function returns the value of the selected expression. If elseexpr is missing and testexpr is nil, then the if function returns nil.
(if (= 1 3) "YES!!" "no.") returns "no."
(if (= 2 (+ 1 1)) "YES!!") returns "YES!!"
(if (= 2 (+ 3 4)) "YES!!") returns nil
(See also the progn function)
initget: Establishes key words for use by the next user-input function call.
(initget [bits] [string])
The functions that honor key words are getint, getreal, getdist, getangle, getorient, getpoint, getcorner, getkword, entsel, nentsel, and nentselp. The getstring function is the only user-input function that does not honor key words. The bits argument is a bit-coded integer that allows or disallows certain types of user input. The string argument defines a list of key words. The key words are checked by the next user-input function call when the user does not enter the expected type of input (for example, a point to getpoint).
If the user input matches a key word from the list, the function returns that key word as a string result. The application can test for the key words and perform the action associated with each one. If the user input is not of the expected type and does not match a key word, AutoCAD asks the user to try again. The initget bit values and key words apply only to the next user-input function call.
The initget function always returns nil.
If initget sets a control bit and the application calls a user-input function for which the bit has no meaning, the bit is ignored. The bits can be added together in any combination to form a value between 0 and 255. If no bits argument is supplied, zero (no conditions) is assumed. If the user input fails one or more of the specified conditions (as in a zero value when zero values are not allowed), AutoCAD displays a message and asks the user to try again.
Input options set by initget.
Bit value : Description
1 (bit 0) : Prevents the user from responding to the request by entering only ENTER.
2 (bit 1) : Prevents the user from responding to the request by entering zero.
4 (bit 2) : Prevents the user from responding to the request by entering a negative value.
8 (bit 3) : Allows the user to enter a point outside the current drawing limits. This condition applies to the next user-input function even if the AutoCAD system variable LIMCHECK is currently set.
16 (bit 4) : (Not currently used.)
32 (bit 5) : Uses dashed lines when drawing rubber-band line or box. For those functions with which the user can specify a point by selecting a location on the graphics screen, this bit value causes the rubber-band line or box to be dashed instead of solid. (Some display drivers use a distinctive color instead of dashed lines.) If the system variable POPUPS is 0, AutoCAD ignores this bit.
64 (bit 6) : Prohibits input of a Z coordinate to the getdist function; lets an application ensure that this function returns a 2D distance. 128 (bit 7) : Allows arbitrary input as if it is a key word, first honoring any other control bits and listed key words. This bit takes precedence over bit 0; if bits 7 and 0 are set and the user presses ENTER, a null string is returned.
Note Future versions of AutoLISP might use additional initget control bits, so avoid setting bits that aren't shown in the table. The special control values are honored only by those getxxx functions for which they make sense. Key Word Specifications: The string argument is interpreted according to these rules: Each key word is separated from the following key word by one or more spaces. For example, "Width Height Depth" defines three key words. Each key word can contain only letters, numbers, and hyphens (-).
There are two methods for abbreviating key words:
The required portion of the key word is specified in uppercase characters, and the remainder of the key word is specified in lowercase characters. The uppercase abbreviation can be anywhere in the key word (for example, "LType", "eXit", or "toP"). The entire key word is specified in uppercase characters, and it is followed immediately by a comma, which is followed by the required characters (for example, "LTYPE,LT"). The key word characters in this case must include the first letter of the key word.
inters: Finds the intersection of two lines.
(inters pt1 pt2 pt3 pt4 [onseg])
The pt1 and pt2 arguments are the endpoints of the first line, and pt3 and pt4 are the endpoints of the second line. If the onseg argument is present and is nil, the lines defined by the four pt arguments are considered infinite in length, and inters returns the point where they intersect even if that point is off the end of one or both of the lines. If the onseg argument is omitted or is not nil, the intersection point must lie on both lines or inters returns nil. The inters function returns nil if the two lines do not intersect. All points are expressed in terms of the current UCS. If all four point arguments are 3D, inters checks for 3D intersection. If any of the points are 2D, inters projects the lines onto the current construction plane and checks only for 2D intersection.
(setq a '(1.0 1.0) b '(9.0 9.0))
(setq c '(4.0 1.0) d '(4.0 2.0))
(inters a b c d): returns nil
(inters a b c d T): returns nil
(inters a b c d nil): returns (4.0 4.0)
itoa: Returns the conversion of an integer into a string.
(itoa int)
The int argument specifies an integer.
(itoa 33) returns "33"
(itoa -17) returns "-17"

L   lambda     last     length     list     listp     load_dialog     load     log     logand     logior     lsh  
lambda: Defines an anonymous function.
(lambda arguments expr...)
Use the lambda function when the overhead of defining a new function is not justified. It also makes the programmer's intention more apparent by laying out the function at the spot where it is to be used. This function returns the value of its last expr, and is often used in conjunction with apply and/or mapcar to perform a function on a list.
(apply '(lambda (x y z)
(* x (- y z))
)
'(5 20 14)
) returns 30
and
(setq counter 0)
(mapcar '(lambda (x)
(setq counter (1+ counter))
(* x 5)
)
'(2 4 -6 10.2)
) returns (10 20 -30 51.0)
last: Returns the last element in a list.
(last lst)
(last '(a b c d e)) returns E
(last '(a b c (d e))) returns (D E)
As shown, last can return an atom or a list.
Note At first glance, last seems a perfect way to obtain the Y coordinate of a point. While this is true for 2D points (lists of two reals), last will return the Z coordinate of a 3D point. To let functions work properly with 2D or 3D points, use cadr to obtain Y coordinates, and caddr to obtain Z coordinates.
length: Returns an integer indicating the number of elements in a list.
(length lst)
(length '(a b c d)) returns 4
(length '(a b (c d))) returns 3
(length '()) returns 0
list: Takes any number of expressions, and combines them into one list.
(list expr...)
(list 'a 'b 'c) returns (A B C)
(list 'a '(b c) 'd) returns (A (B C) D)
(list 3.9 6.7) returns (3.9 6.7)
In AutoLISP, this function is frequently used to define a 2D or 3D point variable (a list of two or three reals). As an alternative to using the list function, you can explicitly quote a list with the quote function if there are no variables or undefined items in the list.
The single quote character ( ' ) is defined as the quote function.
'(3.9 6.7) means the same as (list 3.9 6.7)
This can be useful for creating association lists and defining points. (See also the quote function)
listp: Verifies that an item is a list.
(listp item)
Returns T if item is a list, and returns nil otherwise.
(listp '(a b c)) returns T
(listp 'a) returns nil
(listp 4.343) returns nil
Note Because nil is both an atom and a list, the listp function returns T when passed nil.
(listp nil) returns T
load_dialog: Loads a DCL file.
(load_dialog dclfile)
The dclfile argument is a string that specifies the DCL file to load. If the dclfile argument does not specify a file extension, .dcl is assumed. Returns a positive integer value (dcl_id) if successful, and returns a negative integer if it can't open the file. The dcl_id is used as a handle in subsequent new_dialog and unload_dialog calls. The load_dialog function searches for files according to the AutoCAD library search path. This function is the complement of unload_dialog. An application can load multiple DCL files with multiple load_dialog calls.
load: Evaluates the AutoLISP expressions in a file.
(load filename [onfailure])
The filename argument is a string that represents the file name. If the filename argument does not specify a file extension, .lsp is assumed. If the load function fails, it returns the value of the onfailure argument. However, if onfailure is not provided, a load failure causes an AutoLISP error. If the operation is successful, load returns the value of the last expression in the file. The filename can include a directory prefix, as in "/function/test1". On DOS systems, a drive letter is also permitted. A forward slash (/) or two backslashes (\\) are valid directory delimiters. If you don't include a directory prefix in the filename string, load searches the AutoCAD library path for the specified file. If the file is found anywhere on this path, load then loads the file. If the onfailure argument is a valid AutoLISP function, it is evaluated. In most cases, the onfailure argument should be a string or an atom. This allows an AutoLISP application calling load to take alternative action upon failure.
For example, assuming that file /fred/test1.lsp contains
(defun MY-FUNC1 (x)
...function body...
)
(defun MY-FUNC2 (x)
...function body...
and that file test2.lsp does not exist, then
(load "/fred/test1") returns MY-FUNC2
(load "\\fred\\test1") returns MY-FUNC2
(load "/fred/test1" "bad") returns MY-FUNC2
(load "test2" "bad") returns "bad"
(load "test2") causes an AutoLISP error.
The load function can be used from within another AutoLISP function, or even recursively (in the file being loaded). (See also the defun function and "Symbol and Function Handling")
log: Returns the natural log of a number as a real.
(log num)
(log 4.5): returns 1.50408
(log 1.22): returns 0.198851
logand: Returns the result of the logical bitwise AND of a list of integers.
(logand int int...)
(logand 7 15 3): returns 3
(logand 2 3 15): returns 2
(logand 8 3 4): returns 0
logior: Returns the result of the logical bitwise inclusive OR of a list of integers.
(logior int int...)
(logior 1 2 4): returns 7
(logior 9 3): returns 11
lsh: Returns the logical bitwise shift of an integer by a specified number of bits.
(lsh int numbits)
If numbits is positive, int is shifted to the left; if negative, to the right. In either case, zero bits are shifted in, and the bits shifted out are discarded. The returned value is positive if the significant bit (bit number 31) contains a 0 after the shift operator, otherwise it is negative.
(lsh 2 1): returns 4
(lsh 2 -1): returns 1
(lsh 40 2): returns 160

M   mapcar     max     mem     member     menucmd     menugroup     min     minusp     mode_tile  
mapcar: Returns a list of the result of executing a function with the individual elements of a list or lists supplied as arguments to the function.
(mapcar function list1... listn)
The number of lists must match the number of arguments required by function.
(setq a 10 b 20 c 30)
(mapcar '1+ (list a b c)) returns (11 21 31)
is equivalent to
(1+ a)
(1+ b)
(1+ c)
except that mapcar returns a list of the results.
The lambda function can specify an anonymous function to be performed by mapcar. This is useful when some of the function arguments are constant or are supplied by some other means.
(mapcar '(lambda (x)
(+ x 3)
)
'(10 20 30)
returns (13 23 33)
max: Returns the largest of the numbers given.
(max number number...)
(max 4.07 -144) returns 4.07
(max -88 19 5 2) returns 19
(max 2.1 4 8) returns 8.0
mem: Displays the current state of AutoLISP's memory.
(mem)
Displays the current state of AutoLISP's memory, and returns nil. It displays the following information: Nodes is the total number of nodes allocated so far, which should equal the node segment size multiplied by the number of segments. Free nodes is the number of nodes currently on the free list as a result of a garbage collection. Segments is the number of node segments allocated. Allocate is the current segment size. Collections is a count of garbage collections, whether automatic or forced.
member: Searches a list for an occurrence of an expression and returns the remainder of the list, starting with the first occurrence of the expression.
(member expr lst)
If there is no occurrence of expr in lst, member returns nil.
(member 'c '(a b c d e)): returns (C D E)
(member 'q '(a b c d e)): returns nil
menucmd: Issues menu commands, or sets and retrieves menu item status.
(menucmd string)
The string argument is a string that specifies a menu area and the value to assign to that menu area. The string argument has the following parameters.
"menu_area=value"
The allowed values of menu_area, shown in the following table, are the same as they are in menu file submenu references.
Menu_area string values.
Menu_area: ;string;;;Menu section
B1-B4: ;For BUTTONS menus: 1 through 4
A1-A4: For AUX menus: ;1 through 4
P0-P16: For pull-down (POP) menus: 0 through 16
I: ;For image tile menus
S: ;For the SCREEN menu
T1-T4: ;For TABLET menus 1 through 4
M: ;For DIESEL string expressions
Gmenugroup.nametag: Specifies a menugroup and name tag.
The value parameter specifies the value that is assigned to menu_area. The menucmd function can switch between subpages in an AutoCAD menu. This function can also force the display of menus. This allows AutoLISP programs to use image tile menus and to display other menus from which the user can make selections. AutoLISP programs can also enable, disable, and place marks in menu items.
The following code displays the image tile menu MOREICONS.
(menucmd "I=moreicons") Loads the MOREICONS image tile menu.
(menucmd "I=*") Displays the menu.
The following code checks the status of the third menu item in the pull-down menu POP11. If the menu item is currently enabled, the menucmd function disables it.
(setq s (menucmd "P11.3=?")) Gets the status of the menu item.
(if (= s "") If the status is an empty string,
(menucmd "P11.3=~") disable the menu item
)
The previous code is not foolproof. In addition to being enabled or disabled, menu items can also receive marks. The code (menucmd "P11.3=?") could return "!.", indicating that the menu item is currently checked. This code would make the assumption that the menu item is disabled and would continue without disabling it. If the code included a call to the wcmatch function, it could check the status for an occurrence of the tilde (~) character and then take appropriate action. The menucmd function also allows AutoLISP programs to take advantage of the DIESEL string expression language. Some things can be done much easier with DIESEL than with the equivalent AutoLISP code. The following code returns a string containing the current day and date:
(menucmd "M=$(edtime,$(getvar,date),DDDD\",\" D MONTH YYYY)")
returns "Sunday, 16 July 2023"
menugroup: Verifies that a menugroup is loaded.
(menugroup groupname)
The groupname argument is a string that specifies the menugroup name. If groupname matches a loaded menugroup the function returns the groupname string; otherwise, it returns nil.
min: Returns the smallest of the numbers given.
(min number number...)
(min 683 -10.0): returns -10.0
(min 73 2 48 5): ;returns 2
(min 2 4 6.7): ;returns 2.0
minusp: Verifies that a number is negative.
(minusp num)
Returns T if number is negative, and returns nil otherwise.
(minusp -1): ;returns T
(minusp -4.293): returns T
(minusp 830.2): returns nil
mode_tile: Sets the mode of a dialog box tile.
(mode_tile key mode)
The key argument is a string that specifies the tile and is case sensitive. The mode argument is an integer value. The mode argument values are described in the following table.
Mode argument values
Value : Description
0 : Enable tile
1 : Disable tile
2 : Set focus to tile
3 : Select edit box contents
4 : Flip image highlighting on or off

N   namedobjdict     nentsel     nentselp     new_dialog     not     nth     null     numberp  
namedobjdict: Returns the entity name of the current drawing's named object dictionary, which is the root of all nongraphical objects in the drawing.
(namedobjdict)
Using the name returned by this function and the dictionary access functions, an application can access the nongraphical objects in the drawing.
nentsel: Prompts the user to select an object (entity) by specifying a point, and provides access to the definition data contained within a complex object.
(nentsel [msg])
The msg argument is a string to be displayed as a prompt. If omitted, the Select objects prompt is issued. The nentsel function prompts the user to select an object. The current Object Snap mode is ignored unless the user specifically requests it. To provide additional support at the Command prompt, nentsel honors key words defined by a previous call to initget. When the selected object is not complex (i.e., not a polyline or block), nentsel returns the same information as entsel. However, if the selected object is a polyline, nentsel returns a list containing the name of the subentity (vertex) and the pick point. This is similar to the list returned by entsel, except that the name of the selected vertex is returned instead of the polyline header. The nentsel function always returns the starting vertex of the selected polyline segment. Picking the third segment of a polyline, for example, returns the third vertex. The Seqend subentity is never returned by nentsel for a polyline. Note that an optimized polyline (lwpolyline entity) is defined in the drawing database as a single entity; it does not contain subentities. Selecting an attribute within a block reference returns the name of the attribute and the pick point. When the selected object is a component of a block reference other than an attribute, nentsel returns a list containing four elements. The first element of the list returned from picking an object within a block is the selected entity's name. The second element is a list containing the coordinates of the point used to pick the object. The third element is called the Model to World Transformation Matrix. It is a list consisting of four sublists, each of which contains a set of coordinates. This matrix can be used to transform the entity definition data points from an internal coordinate system called the Model Coordinate System (MCS), to the World Coordinate System (WCS). The insertion point of the block that contains the selected entity defines the origin of the MCS. The orientation of the UCS when the block is created determines the direction of the MCS axes. The fourth element is a list containing the entity name of the block that contains the selected object. If the selected object is in a nested block (a block within a block), the list additionally contains the entity names of all blocks in which the selected object is nested, starting with the innermost block and continuing outward until the name of the block that was inserted in the drawing is reported.
(: Name of entity
(Px Py Pz): ;Pick point
( (X0 Y0 Z0): Model to World Transformation Matrix
(X1 Y1 Z1)
(X2 Y2 Z2)
(X3 Y3 Z3)
)
( Name of most deeply nested block
. containing selected entity
.
.
) Name of outermost block
) containing selected entity
Once the entity name and the Model to World Transformation Matrix are obtained, you can transform the entity definition data points from the MCS to the WCS. Use entget and assoc on the entity name to obtain the definition points expressed in MCS coordinates. The Model to World Transformation Matrix returned by nentsel has the same purpose as that returned by nentselp, but it is a 4x3 matrix--passed as an array of four points--that uses the convention that a point is a row rather than a column. The transformation is described by the following matrix multiplication:
So the equations for deriving the new coordinates are as follows:
The Mij, where 0 i, j 2, are the Model to World Transformation Matrix coordinates; X, Y, Z is the entity definition data point expressed in MCS coordinates, and X', Y', Z' is the resulting entity definition data point expressed in WCS coordinates.
Note This is the only AutoLISP function that uses a matrix of this type; the nentselp function returns a matrix similar to those used by other AutoLISP and ADSRX functions. (See also "Entity Name Functions" and the entsel and if functions)
nentselp: Provides similar functionality to that of the nentsel function without the need for user input.
(nentselp [msg] [pt])
In addition to the optional msg argument, nentselp accepts a selection point as an optional argument. This allows object selection without user input. The nentselp function returns a 4x4 transformation matrix, defined as follows: The first three columns of the matrix specify scaling and rotation. The fourth column is a translation vector. The functions that use a matrix of this type treat a point as a column vector of dimension 4. The point is expressed in homogeneous coordinates, where the fourth element of the point vector is a scale factor that is normally set to 1.0. The final row of the matrix, the vector [M30 M31 M32 M33], has the nominal value of [0 0 0 1]; it is currently ignored by the functions that use this matrix format. In this convention, applying a transformation to a point is a matrix multiplication that appears as follows:
This multiplication gives us the individual coordinates of the point as follows: As these equations show, the scale factor and the last row of the matrix have no effect and are ignored.
new_dialog: Begins a new dialog box and displays it, and can also specify a default action.
(new_dialog dlgname dcl_id [action [screen-pt]])
The dlgname argument is a string that specifies the dialog box, and dcl_id identifies the DCL file (you must have obtained its value from the load_dialog call). The action argument, which must be specified if you specify screen-pt, is a string that contains an AutoLISP expression to use as the default action. If you don't want to define a default action, pass action as the empty string ("").
The screen-pt argument is a 2D point list that specifies the X,Y location of the dialog box on the screen. The point usually specifies the upper-left corner of the dialog box, but this is platform dependent, as is the system of units in which the location is specified. If you pass the point as'(-1 -1), the dialog box is opened in the default position (the center of the AutoCAD graphics screen). If new_dialog succeeds, it returns T; otherwise it returns nil. Your application must call new_dialog before it calls start_dialog. All dialog box initialization--such as setting tile values, creating images or lists for list boxes, and associating actions with specific tiles (with the use of action_tile)--must take place after the new_dialog call and before the start_dialog call. The default action is evaluated when the user picks an active tile that doesn't have an action or callback explicitly assigned to it by action_tile or in DCL. Note that always check the status new_dialog returns. Calling start_dialog when the new_dialog call failed can have unpredictable results.
not: Verifies that an item evaluates to nil.
(not item)
Returns T if item evaluates to nil, and returns nil otherwise.
(setq a 123 b "string" c nil)
(not a) returns nil
(not b) returns nil
(not c) returns T
(not '()) returns T
Typically, the null function is used for lists, and not is used for other data types along with some type of control function.
nth: Returns the nth element of a list.
(nth n lst)
The n argument is the number of the element to return (zero is the first element). If n is greater than lst's highest element number, nth returns nil.
(nth 3 '(a b c d e)) returns D
(nth 0 '(a b c d e)) returns A
(nth 5 '(a b c d e)) returns nil
null: Verifies that an item is bound to nil.
(null item)
Returns T if item is bound to nil, and returns nil otherwise.
(setq a 123 b "string" c nil)
(null a) returns nil
(null b) returns nil
(null c) returns T
(null '()) returns T
numberp: Verifies that an item is a real or an integer.
(numberp item)
Returns T if item is a real or an integer, and returns nil otherwise.
(setq a 123 b 'a)
(numberp 4): returns T
(numberp 3.8348) returns T
(numberp "Howdy"): returns nil
(numberp a): ;returns T
(numberp b): ;returns nil
(numberp (eval b)): returns T

O   open     or     osnap  
open: Opens a file for access by the AutoLISP I/O functions.
(open filename mode)
The filename argument is a string that specifies the name and extension of the file to be opened. The mode argument is the read/write flag. It must be a string containing a single lowercase letter. The following table describes the valid mode letters.
Mode options for the open function
Open mode;Description
"r" : Open for reading. If filename does not exist, open returns nil.
"w" : Open for writing. If filename does not exist, a new file is created and opened. If filename already exists, its existing data is overwritten.
"a" : Open for appending. If filename does not exist, a new file is created and opened. If filename already exists, it is opened and the pointer is positioned at the end of the existing data, so new data you write to the file is appended to the existing data.
Data passed to an open file is not actually written until th e file is closed with the close function. On DOS systems, some programs and text editors write text files with an end-of-file marker (CTRL Z, decimal ASCII code 26) at the end of the text. When reading a text file, DOS returns an end-of-file status if a CTRL Z marker is encountered, even if that marker is followed by more data. If you intend to use OPEN's "a" mode to append data to files produced by another program, be sure that the other program does not insert CTRL Z markers at the end of its text files. The open function returns a file descriptor to be used by the other I/O functions. The file descriptor must be assigned to a symbol that uses the setq function.
(setq a (open "file.ext" "r"))
Assuming that the files named in the following examples do not exist,
(setq f (open "new.tst" "w")) returns
(setq f (open "nosuch.fil" "r")) returns nil
(setq f (open "logfile" "a")) returns
The filename argument can include a directory prefix, as in /test/func3. On DOS systems, a drive letter is also permitted, and you can use the backslash (\) instead of the forward slash (/), but remember that you must use two backslashes (\\) to obtain one backslash in a string.
(setq f (open "/x/new.tst" "w")) returns
(setq f (open "nosuch.fil" "r")) returns nil
or: Returns the logical OR of a list of expressions.
(or expr...)
The or function evaluates the expressions from left to right, looking for a non-nil expression. If one is found, or ceases further evaluation and returns T. If all of the expressions are nil, or returns nil.
(or nil 45 '()): returns T
(or nil '()): returns nil
osnap: Returns a 3D point that is the result of applying an Object Snap mode to a specified point.
(osnap pt mode)
The mode argument is a string that consists of one or more valid Object Snap identifiers such as mid, cen, and so on, separated by commas.
(setq pt1 (getpoint))
(setq pt2 (osnap pt1 "cen"))
(setq pt3 (osnap pt1 "end,int"))
The point returned by osnap depends on the current 3D view and the setting of the APERTURE system variable.

P   polar     prin1     princ     print     progn     prompt  
polar: Returns the UCS 3D point at a specified angle and distance from a point.
(polar pt ang dist)
The ang argument is expressed in radians relative to the X axis with angles increasing in the counterclockwise direction. Although pt can be a 3D point, ang is always with respect to the current construction plane.
(polar '(1 1 3.5) 0.785398 1.414214) returns (2.0 2.0 3.5)
prin1: Prints an expression to the command line or writes an expression to an open file.
(prin1 [expr [file-desc]])
The expr argument does not need to be a string. If file-desc is present and is a file descriptor for a file opened for writing, expr is written to the file exactly as it appears on the screen. Only the specified expr is printed; no newline or space is included.
(setq a 123 b '(a))
(prin1 'a) prints A and returns A
(prin1 a) prints 123 and returns 123
(prin1 b) prints (A) and returns (A)
(prin1 "Hello") prints "Hello" and returns "Hello"
Each of the preceding examples is displayed on the screen because no file-desc was specified. Assuming that f is a valid filedescriptor for a file opened for writing,
(prin1 "Hello" f) will write "Hello" to the specified file and will return "Hello".
If expr is a string containing control characters, prin1 expands these characters with a leading \, as shown in the following table.
Control codes
Code;Description
\\: \ character
\": " character
\e: Escape character
\n: Newline character
\r: Return character
\t: Tab character
\nnn: Character whose octal code is nnn
\U+XXXX: Unicode sequence
\M+NXXXX: Unicode sequence
The following examples show how to use control characters:
(prin1 (chr 2)) prints "\002" and returns "\002"
(prin1 (chr 10)) prints "\n" and returns "\n"
The prin1 function can be called with no arguments, in which case it returns (and prints) the null string. If you use prin1 (with no arguments) as the last expression in a user-defined function, only a blank line is printed when the function is complete, allowing the application to exit "quietly." (See also "Displaying Messages on the Command Line")
princ: Prints an expression to the command line, or writes an expression to an open file.
(princ [expr [file-desc]])
This function is the same as prin1, except that control characters in expr are printed without expansion. In general, prin1 is designed to print expressions in a way that is compatible with load, while princ prints them in a way that is readable by functions such as read-line.
print: Prints an expression to the command line, or writes an expression to an open file.
(print [expr [file-desc]])
This function is the same as prin1, except that it prints a newline character before expr, and prints a space following expr.
progn: Evaluates each expression sequentially, and returns the value of the last expression.
(progn [expr]...)
You can use progn to evaluate several expressions where only one expression is expected.
(if (= a b)
;(progn
;;(princ "\nA = B ")
;;(setq a (+ a 10) b (- b 10))
;)
)
The if function normally evaluates one then expression if the test expression evaluates to anything but nil. In this example, we have used progn to cause two expressions to be evaluated instead.
prompt: Displays a string on your screen's prompt area.
(prompt msg)
On dual-screen AutoCAD configurations, prompt displays msg on both screens and is, therefore, preferable to princ.
(prompt "New value: ") displays New value: on the screen(s)
The prompt function returns nil.

Q   quit     quote  
quit: Forces the current application to quit.
(quit)
If quit is called, it returns the error message quit/exit abort and returns to the AutoCAD Command prompt. (See also the exit function)
quote: Returns an expression without evaluating it.
(quote expr)
This can also be written
'expr
(quote a) returns A
(quote cat) returns CAT
(quote (a b)) returns (A B)
'a returns A
'cat returns CAT
'(a b) returns (A B)
The last three examples don't work if entered directly from the keyboard in response to an AutoCAD prompt. Remember that such input must begin with the character ( or ! to be recognized as an AutoLISP expression.

R   read     read-char     read-line     redraw     regapp     rem     repeat     reverse     rtos  
read: Returns the first list or atom obtained from a string.
(read [string])
The string argument cannot contain blanks except within a list or string. The read function returns its argument converted into the corresponding data type:
(read "hello"): ;returns the atom HELLO
(read "hello there"): returns the atom HELLO
(read "\"Hi Y'all\""): returns the string "Hi Y'all"
(read "(a b c)"): ;returns the list (A B C)
(read "(a b c) (d)"): ;returns the list (A B C)
(read "1.2300"): ;returns the real number 1.23
(read "87"): ;returns the integer 87
(read "87 3.2"): ;returns the integer 87
read-char: Returns the decimal ASCII code representing the character read from the keyboard input buffer or from an open file.
(read-char [file-desc])
If no file-desc is specified and there are no characters in the keyboard input buffer, read-char waits for keyboard entry (followed by ENTER). For instance, assuming the keyboard input buffer is empty, (read-char) waits for something to be entered. If you enter ABC followed by ENTER, read-char returns 65 (the decimal ASCII code for the letter A). The next three calls to read-char return 66, 67, and 10 (newline), respectively. If another read-char call is made, it again waits for input. The various operating systems under which AutoCAD runs use various conventions to signal the end of a line in an ASCII text file. UNIX systems, for example, use a single newline character (linefeed [LF], ASCII code 10), whereas DOS systems use a pair of characters (carriage-return [CR]/LF, ASCII codes 13 and 10) for the same purpose. To facilitate development of AutoLISP programs, read-char accepts all these conventions, returning a single newline character (ASCII code 10) whenever it detects an end-of-line character (or character sequence).
read-line: Reads a string from the keyboard or from an open file.
(read-line [file-desc])
If read-line encounters the end of the file, it returns nil; otherwise it returns the string that it read. For example, assuming that f is a valid open file pointer, (read-line f) returns the next input line from the file, or returns nil if the end-of-file has been reached.
redraw: Redraws the current viewport or a specified object (entity) in the current viewport.
(redraw [ename [mode]])
The effect of the redraw function depends on the arguments supplied. If called with no arguments, it redraws the current viewport. If called with the ename (entity name) argument, it redraws the specified entity. The mode argument is an integer value that controls the visibility and highlighting of the entity.
Modes for redraw
Redraw mode;Action
1 : Show entity
2 : Hide entity (blank it out)
3 : Highlight entity
4 : Unhighlight entity
If ename is the header of a complex entity (a polyline or a block reference with attributes), it processes the main entity and all its subentities if the mode argument is positive. If the mode argument is negative, redraw operates on only the header entity. The redraw function always returns nil. The use of entity highlighting (mode 3) must be balanced with entity unhighlighting (mode 4). The REDRAW command has no effect on highlighted or hidden entities; however, a REGEN forces the entities to redisplay in their normal manner.
regapp: Registers an application name with the current AutoCAD drawing in preparation for using extended object data.
(regapp application)
The application argument is a string up to 31 characters long that adheres to the symbol-naming conventions. An application name can contain letters, digits, and the special characters dollar sign ($), hyphen (-), and underscore (_). It cannot contain spaces. Letters in the name are converted to upper case. If an application of the same name has already been registered, this function returns nil; otherwise it returns the name of the application. If registered successfully, the application name is entered into the APPID symbol table. This table maintains a list of the applications that are using extended data in the drawing.
(regapp "ADESK_4153322344")
(regapp "DESIGNER-v2.1-124753")
Note It is recommended that you pick a unique application name. One way of ensuring this is to adopt a naming scheme that uses the company or product name and a unique number (like your telephone number or the current date/time). The product version number can be included in the application name or stored by the application in a separate integer or real-number field; for example,
(1040 2.1).
rem: Divides the first number by the second, and returns the remainder.
(rem number number...)
If more than two numbers are provided, rem divides the result of dividing the first number by the second with the third, and so on.
(rem 42 12): returns 6
(rem 12.0 16): returns 12.0
(rem 26 7): returns 5
(rem 5 2): returns 1
(rem 26 7 2): returns 1
repeat: Evaluates each expression a specified number of times, and returns the value of the last expression.
(repeat int expr...)
The int argument must be positive.
(setq a 10 b 100)
(repeat 4
(setq a (+ a 10))
(setq b (+ b 100))
) Sets a to 50, sets b to 500, and returns 500
reverse: Returns a list with its elements reversed.
(reverse lst)
(reverse '((a) b c)): returns (C B (A))
rtos: Converts a number into a string.
(rtos number [mode [precision]])
The rtos function returns a string that is the representation of number according to the settings of mode, precision, and the system variables UNITMODE and DIMZIN. The mode and precision arguments are integers that select the linear units mode and precision, as shown in the following table.
Linear units values
Mode value;String format
1 : Scientific
2 : Decimal
3 : Engineering (feet and decimal inches)
4 : Architectural (feet and fractional inches)
5 : Fractional
The mode and precision arguments correspond to the system variables LUNITS and LUPREC. If you omit the arguments, rtos uses the current settings of LUNITS and LUPREC. The UNITMODE variable affects the returned string when engineering, architectural, or fractional units are selected (a mode value of 3, 4, or 5). (See also "String Conversions," which continues the discussion of rtos)

S   set     set_tile     setcfg     setfunhelp     setq     setvar     setview     sin     slide_image     snvalid     sqrt     ssadd     ssdel     ssget     ssgetfirst     sslength     ssmemb     ssname     ssnamex     sssetfirst     startapp     start_dialog     start_image     start_list     strcase     strcat     strlen     subst        
set: Sets the value of a quoted symbol name to an expression.
(set sym expr)
Returns the value of the expression.
(set 'a 5.0): returns 5.0 and sets symbol A
(set (quote b) 'a) returns A and sets symbol B
If set is used with an unquoted symbol name, it can assign a new value to another symbol indirectly. For instance, given the previous examples (set b 640): returns 640
and assigns the value 640 to symbol a, because that is what symbol b contains. (See also the setq function)
set_tile: Sets the value of a dialog box tile.
(set_tile key value)
The key argument is a string that specifies the tile, and value is a string that names the new value to assign (initially set by the value attribute).
setcfg: Writes application data to the AppData section of the acad.cfg file.
(setcfg cfgname cfgval)
The cfgname argument is a string (132 characters maximum length) that specifies the section and parameter to set the value of cfgval (347 characters max. length). If cfgname is not valid, setcfg returns nil. The cfgname argument must be a string of the following form: "AppData/application_name/section_name/.../param_name". The following code sets the WallThk parameter in the AppData/ArchStuff section to 8 and returns the string "8":
(setcfg "AppData/ArchStuff/WallThk" "8") returns "8"
(See also the getcfg function)
setfunhelp: Registers a user-defined command with the Help facility so that the appropriate help file and topic are called when the user requests help on that command.
(setfunhelp c:fname [helpfile [topic [command]]])
The c:fname argument is a string that specifies the user-defined command (the C:XXX function) and must include the C: prefix. Unlike the function name passed to the defun function, the function argument for setfunhelp must be a quoted string. The remaining three optional arguments describe the help call to be made. They are also strings and are the same as the arguments passed to the help function. The setfunhelp function returns the string passes as c:fname if successful otherwise, it returns nil. The file extension is not required with the helpfile argument. If a file extension is provided, AutoCAD looks only for that file. If no file extension is provided, the following search rules apply: If this is AutoCAD for Windows/NT, append .hlp, else append .ahp. If no .ahp file is found, search for with no extension. Note that the file with no extension is searched last, so on UNIX, acad.ahp is searched before acad. It should be noted that this function verifies only that the c:fname argument has the c:prefix. It does not verify that the c:fname function exists or the correctness of the other arguments. When you use the defun function to define a C:XXX function, it removes that function's name from those registered by setfunhelp (if one exists). Therefore, setfunhelp should only be called after the defun call, which defines the user-defined command. The following example uses defun to define the user-defined command MYFUN. The setfunhelp function registers the function name C:MYFUN and associates that name with the topic myfun in the file myhelp.ahp.
(defun c:myfun ()
;...
;(getint "gimme: ")
;...
)
(setfunhelp "c:myfun" "myhelp.ahp" "myfun")
Command: myfun
gimme: 'help
Assuming that the AutoCAD Help file myhelp.ahp exists in the support path, AutoCAD displays the Help dialog with the topic myfun from the file myapp.ahp. (See also the defun and help functions)
setq: Sets the value of a symbol or symbols to associated expressions.
(setq sym1 expr1 [sym2 expr2]...)
This is the basic assignment function in AutoLISP. The setq function can assign multiple symbols in one call to the function, but returns only the last expr.
(setq a 5.0) returns 5.0
and sets the symbol a to 5.0. Whenever a is evaluated, it evaluates the real number 5.0.
(setq b 123 c 4.7) returns 4.7
(setq s "it") returns "it"
(setq x '(a b)) returns (A B)
(See also "AutoLISP Variables")
setvar: Sets an AutoCAD system variable to a specified value.
(setvar varname value)
If successful, setvar returns the value of the system variable. You must enclose the variable name in quotation marks.
(setvar "FILLETRAD" 0.50) returns 0.5 and sets the AutoCAD fillet radius to 0.5 units. For system variables with integer values, the supplied value must be between -32,768 and +32,767. Some AutoCAD commands obtain the values of system variables before issuing any prompts. If you use setvar to set a new value while a command is in progress, the new value might not take effect until the next AutoCAD command. When using the setvar function to change the AutoCAD system variable ANGBASE, the value argument is interpreted as radians. This differs from the AutoCAD SETVAR command, which interprets this argument as degrees. When using the setvar function to change the AutoCAD system variable SNAPANG, the value argument is interpreted as radians relative to the AutoCAD default direction for angle 0, which is east or 3 o'clock. This also differs from the SETVAR command, which interprets this argument as degrees relative to the ANGBASE setting. The UNDO command does not undo changes made to the CVPORT system variable by the setvar function.
setview: Establishes a view for a specified viewport.
(setview view_descriptor [vport_id])
The view_descriptor argument is an entity definition list similar to that returned by tblsearch when applied to the VIEW symbol table. The optional argument vport_id identifies which viewport is to receive the new view. The vport_id number can be retrieved by the CVPORT system variable. If vport_id is 0, the current viewport receives the new view. If successful, the setview function returns the view_descriptor.
slide_image: Displays an AutoCAD slide in the currently active dialog box image tile.
(slide_image x1 y1 wid hgt sldname)
The slide can be a slide file (.sld) or a slide in a slide library file (.slb): the sldname argument specifies it as you would specify it for the VSLIDE command or for a menu file. The first (upper-left) corner of the slide--its insertion point--is located at (x1,y1), and the second (lower-right) corner is located at the relative distance (wid,hgt) from the first (wid and hgt must be positive values). The origin (0,0) is the upper-left corner of the image. You obtain the coordinates of the lower-right corner by calling the dimension functions (dimx_tile and dimy_tile).
sin: Returns the sine of an angle as a real expressed in radians.
(sin ang)
The ang argument must be an angle expressed in radians.
(sin 1.0) returns 0.841471
(sin 0.0) returns 0.0
snvalid: Checks the symbol table name for valid characters.
(snvalid sym_name [flag])
The sym_name argument is a string that specifies a symbol table name. The optional flag argument specifies whether the vertical bar character is allowed in sym_name. The flag argument can be 1 or 0 (default is 0). The snvalid function returns T if sym_name is a valid symbol table name, otherwise it returns nil. Symbol table names must consist of only alphanumeric characters and the special characters dollar sign ($), underscore (_), and hyphen (-). A null string is not a valid name.
sqrt: Returns the square root of a number as a real.
(sqrt num)
(sqrt 4): returns 2.0
(sqrt 2.0): returns 1.41421
ssadd: Adds an object (entity) to a selection set, or creates a new selection set.
(ssadd [ename [ss]])
If called with no arguments, ssadd constructs a new selection set with no members. If called with the single entity name argument ename, ssadd constructs a new selection set containing that single entity. If called with an entity name and the selection set ss, ssadd adds the named entity to the selection set. The ssadd function always returns the new or modified selection set. When adding an entity to a set, the new entity is added to the existing set, and the set passed as ss is returned as the result. Thus, if the set is assigned to other variables, they also reflect the addition. If the named entity is already in the set, the ssadd operation is ignored and no error is reported.
(setq e1 (entnext)) Sets e1 to name of first entity in drawing
(setq ss (ssadd)) Sets ss to a null selection set
(ssadd e1 ss) Returns ss with entity name e1 added
(setq e2 (entnext e1)) Gets entity following e1
(ssadd e2 ss) Returns ss with entity name e2 added
ssdel: Deletes an object (entity) from a selection set.
(ssdel ename ss)
The ssdel function deletes the entity ename from selection set ss and returns the name of selection set ss. Note that the entity is actually deleted from the selection set as opposed to a new set being returned with the element deleted. If the entity is not in the set, nil is returned. For example, given that entity name e1 is a member of selection set ss1 and entity name e2 is not, then
(ssdel e1 ss1) Returns selection set ss with entity e1 removed
(ssdel e2 ss1) Returns nil (does not change ss1)
ssget: Prompts the user to select objects (entities), and returns a selection set.
(ssget [mode] [pt1 [pt2]] [pt-list] [filter-list])
The mode argument is a string that specifies the object selection method. Valid modes are "W", "WP", "C", "CP", "L", "P", "I", and "F", corresponding to the Window, WPolygon, Crossing, CPolygon, Last, Previous, Implied, and Fence selection methods. Another optional mode value is "X", which selects the entire database. The pt1 and pt2 arguments specify points relevant to the selection.
Supplying a point with no mode argument is equivalent to object selection by picking a single point. The current setting of Object Snap mode is ignored by this function unless you specifically request it while you are in the function. The filter-list argument is an association list that specifies object properties. Objects that match the filter-list are added to the selection set. If all arguments are omitted, ssget prompts the user with the Select objects prompt, allowing interactive construction of the selection set. Selection sets can contain objects from both paper and model space, but when the selection set is used in an operation, objects from the space not currently in effect are filtered out. Selection sets returned by ssget contain main entities only (no attributes or polyline vertices).
(ssget): ;Asks the user for a general object selection and places those objects in a selection set
(ssget "P"): ;Creates a selection set of the most recently selected objects
(ssget "L"): ;Creates a selection set of the last visible object added to the database
(ssget "I"): ;Creates a selection set of the objects in the implied selection set (those selected while PICKFIRST is in effect)
(ssget '(2 2)): ;Creates a selection set of the object passing through (2,2)
(ssget "W" '(0 0) '(5 5)): Creates a selection set of the objects inside the window from (0,0) to (5,5)
(ssget "C" '(0 0) '(1 1)): Creates a selection set of the objects crossing the box from (0,0) to (1,1)
(ssget "X"): ;Creates a selection set of all objects in the database
(ssget "X" filter-list): Scans the database and creates a selection set of objects matching the filter-list
(ssget filter-list): Asks the user for a general object selection and places only those objects matching the filter-list in a selection set
(ssget "P" filter-list): Creates a selection set of the most recently selected objects that match the filter-list.
The following examples of ssget require that a list of points be passed to the function. The pt_list variable cannot contain points that define zero-length segments.
(setq pt_list '((1 1)(3 1)(5 2)(2 4)) )
(ssget "WP" pt_list): Creates a selection set of all objects inside the polygon defined by pt_list
(ssget "CP" pt_list): Creates a selection set of all objects crossing and inside the polygon defined by pt_list
(ssget "F" pt_list): Creates a selection set of all objects intersecting the fence defined by pt_list
(ssget "WP" pt_list filter-list) Creates a selection set of all objects inside the polygon defined by pt_list that match the filter-list
The selected objects are highlighted only when ssget is used with no arguments. Selection sets consume AutoCAD temporary file slots, so AutoLISP is not permitted to have more than 128 open at once. If this limit is reached, AutoCAD refuses to create any more selection sets and returns nil to all ssget calls. To close an unneeded selection set variable, set it to nil. A selection set variable can be passed to AutoCAD in response to any Select objects prompt at which selection by Last is valid. It selects all the objects in the selection set variable.
Selection Set Filters: Selection set filter lists can be used with any of the selection modes. You can obtain a selection set that includes all objects of a given type, on a given layer, or of a given color.
The following example returns a selection set that consists only of blue lines that are part of the Implied selection set (those objects selected while PICKFIRST is in effect):
(ssget "I" '((0 . "LINE") (62 . 5))) Using the ssget filter list, you can select all objects containing extended data for a particular application. You do this by using the -3 group code, as in (ssget "P" '((0 . "CIRCLE") (-3 ("APPNAME"))))
This selects all circles containing data for the "APPNAME" application.
Relational Tests: Unless otherwise specified, an "equals" test is implied for each item in the filter-list. For numeric groups (integers, reals, points, and vectors) you can specify other relations by including a special -4 group code that specifies a relational operator. The value of a -4 group is a string that indicates the test operator to be applied to the next group in the filter list.
(ssget "X" '((0 . "CIRCLE") (-4 . ">=") (40 . 2.0)))
selects all circles whose radius (group code 40) is greater than or equal to 2.0. The following table shows the possible operators.
Relational operators for selection set filter lists
Operator : Description
"*": Anything goes (always true)
"=": Equals
"!=": Not equal to
"/=": Not equal to
"<>": Not equal to
"<": Less than
"<=": Less than or equal to
">": Greater than
">=": Greater than or equal to
"&": Bitwise AND (integer groups only)
"&=": Bitwise masked equals (integer groups only)
The use of relational operators depends on the kind of group you are testing: All relational operators except for the bitwise operators ("&" and "&=") are valid for both real- and integer-valued groups.
The bitwise operators "&" and "&=" are valid only for integer-valued groups. The bitwise AND, "&", is true if ((integer_group & filter) /= 0)--that is, if any of the bits set in the mask are also set in the integer group. The bitwise masked equals, "&=", is true if ((integer_group & filter) = filter)--that is, if all bits set in the mask are also set in the integer_group (other bits might be set in the integer_group but are not checked).
For point groups, the X, Y, and Z tests can be combined into a single string, with each operator separated by commas (for example, ">,>,*"). If an operator is omitted from the string (for example, "=,<>" leaves out the Z test), the "anything goes" operator, "*", is assumed. Direction> # end of Marker vectors (group type 210) can be compared only with the operators "*", "=", and "!=" (or one of the equivalent "not equal" strings). You cannot use the relational operators with string groups; use wild-card tests instead.
Logical Grouping of Filter Tests: The relational operators described in the previous subsection are binary operators. You can also test groups by creating nested Boolean expressions that use the grouping operators shown in the following table. The grouping operators are specified by -4 groups, like the relational operators. They are paired, and must be balanced correctly in the filter list or the ssget call fails. The number of operands these operators can enclose depends on the operation.
Grouping operators for selection set filter lists
Starting Encloses Ending
operator operator
""
""
""
""
With the grouping operators, an operand is an entity-field group, a relational operator followed by an entity-field group, or a nested expression created by these operators. The following is an example of grouping operators in a filter list:
(ssget "X" '((-4 . " ;(-4 . " ;(0 . "CIRCLE")
;(40 . 1.0)
;(-4 . "AND>")
;(-4 . " ;(0 . "LINE")
;(8 . "ABC")
;(-4 . "AND>")
;(-4 . "OR>"))
)
This selects all circles with radius 1.0, plus all lines on layer "ABC". Because the grouping operators are not case-sensitive, you can also use their lowercase equivalents: "", "", "", "".
ssgetfirst: Determines which objects are selected and gripped.
(ssgetfirst)
Returns a list of two selection sets similar to those passed to sssetfirst. The first element in the list is a selection set of entities that are gripped but not selected. The second element is a selection set of entities that are both gripped and selected. Either (or both) elements of the list can be nil. Only entities from the current drawing's model space and paper space, not nongraphical objects or entities in other block definitions, can be analyzed by this function.
sslength: Returns an integer containing the number of objects (entities) in a selection set.
(sslength ss)
The number is returned as a real if it is greater than 32,767. Selection sets never contain duplicate selections of the same entity.
(setq sset (ssget "L")) Places the last object in selection set sset
(sslength sset) returns 1
ssmemb: Tests whether an object (entity) is a member of a selection set.
(ssmemb ename ss)
If it is, ssmemb returns the entity name (ename). If not, it returns nil. For example, given that entity name e1 is a member of selection set ss1 and entity name e2 is not, then
(ssmemb e1 ss1) returns entity name e1
(ssmemb e2 ss1) returns nil
ssname: Returns the object (entity) name of the indexed element of a selection set.
(ssname ss index)
The index argument must be an integer. If index is negative or greater than the highest numbered entity in the selection set, nil is returned. The first element in the set has an index of zero. Entity names in selection sets obtained with ssget always are names of main entities. Subentities (attributes and polyline vertices) are not returned. (The entnext function allows access to them. See "entnext.")
(setq sset (ssget)) Creates a selection set named sset
(setq ent1 (ssname sset 0)) Gets name of first entity in sset
(setq ent4 (ssname sset 3)) Gets name of fourth entity in sset
To access entities beyond the 32767th one in a selection set, you must supply the index argument as a real. For example:
(setq entx (ssname sset 50843.0)) Gets name of 50844th entity in sset.
ssnamex: Retrieves information about how a selection set was created.
(ssnamex ss [index])
This function returns the entity name of the element specified by index from the selection set ss along with data that describes how the entity was selected. If the index argument is not supplied, this function returns a list containing the entity names of all of the elements in the selection set along with data that describes how each of the entities was selected. The data returned by ssnamex takes the form of a list of lists that contains information that either describes an entity and its selection method or a polygon that was used to select one or more entities. Each sub-list that describes the selection of a particular entity comprises three parts: the selection method ID (an integer >= 0), the entity name of the selected entity, and selection method specific data that describes how the entity was selected.
((sel_id1 ename1 (data))(sel_id2 ename2 (data)) ... )
The following table lists the selection method IDs.
Selection method IDs
ID : Description
0: non specific (i.e. Last All etc.)
1: Pick
2: Window or WPolygon
3 : Crossing or CPolygon
4: Fence
Each sub-list that describes a polygon that's used during entity selection takes the form of a polygon ID (an integer < 0), followed by point descriptions.
(polygon_id point_description_1 point_description_n... )
Polygon ID numbering starts at -1 and each additional polygon ID is incremented by -1. Depending on the viewing location, a point is represented as one of the following: an infinite line, a ray, or a line segment. A point descriptor comprises three parts: a point descriptor ID (the type of item being described), the start point of the item, and an optional unit vector that describes either the direction in which the infinite line travels or a vector that describes the offset to the other side of the line segment.
(point_descriptor_id base_point [unit_or_offset_vector])
The following table lists the valid point descriptor IDs.
Point descriptor IDs
ID : Description
0: Infinite line
1: Ray
2: Line segment
The unit_or_offset_vector is returned when the view point is something other than 0,0,1. The data associated with Pick (type 1) entity selections is a single point description. For example, the following record is returned for the selection of an entity picked at
1,1 in plan view of the WCS:
(1 (0 (1.0 1.0 0.0) ) )
The data associated with an entity selected with the Window, WPolygon, Crossing, or CPolygon method is the integer ID of the polygon that selected the entity. It is up to the application to associate the polygon identifiers and make the connection between the polygon and the entities it selected. For example, the following record is returned for an entity selected by Crossing (note that the polygon ID is -1).
((3 -1) (-1 (0 (5.14828 7.05067 0.0) ) (0 (7.13676 7.05067 0.0) ) (0 (7.13676 4.62785 0.0) ) (0 (5.14828 4.62785 0.0) ) ) )
The data associated with Fence selections is a list of points descriptions for the points where the fence and entity visually intersect.
For example, the following record is returned for a nearly vertical line intersected three times by a Z-shaped fence. ((4 (0 (5.28135 6.25219 0.0) ) (0 (5.61868 2.81961 0.0) ) (0 (5.52688 3.75381 0.0) ) ) )
Note Only selection sets with entities from the current drawing's model space and paper space--not nongraphical objects or entities in other block definitions--can be retrieved by this function.
sssetfirst: Sets which objects are selected and gripped.
(sssetfirst gripset [pickset])
The selection set of objects specified by the gripset argument are gripped, and the selection set of objects specified by pickset are both gripped and selected. If any objects are common to both selection sets, sssetfirst grips and selects the selection set specified by pickset only (it does not grip the gripset set). If gripset is nil sssetfirst grips and selects the pickset set. The sssetfirst function returns a list of the two variables passed as the selection sets. Do not call ads_ssetfirst() when AutoCAD is in the middle of executing a command.
startapp: Starts a Windows application.
(startapp appcmd [file])
The appcmd argument is a string that specifies the application to execute. If appcmd does not include a full path name, it searches the PATH environment variable for the application. The file argument is a string that specifies the file name to be opened. Returns an integer greater than 0 if successful; otherwise it returns 0. The following code starts the Windows Notepad and opens the acad.lsp file.
(startapp "notepad" "acad.lsp")
If an argument has embedded spaces, it must be surrounded by literal double quotes. For example, to edit the file my stuff.txt with Notepad use the following syntax: (startapp "notepad.exe" "\"my stuff.txt\""). Externally defined function acadapp ARX application.
start_dialog: Displays a dialog box and begins accepting user input.
(start_dialog)
You must first initialize the dialog box by a previous new_dialog call. The dialog box remains active until an action expression or callback function calls done_dialog. Usually done_dialog is associated with the tile whose key is "accept" (typically the OK button) and the tile whose key is "cancel" (typically the Cancel button). The start_dialog function has no arguments. It returns the optional status passed to done_dialog. The default value is 1 if the user pressed OK, 0 if the user pressed Cancel, or -1 if all dialog boxes were terminated with term_dialog. But if done_dialog is passed an integer status greater than 1, start_dialog returns this value, whose meaning depends on the application.
start_image: Starts the creation of an image in the dialog box tile.
(start_image key)
Subsequent calls to fill_image, slide_image, and vector_image affect this image until the application calls end_image. The key argument is a string that specifies the dialog box tile. The key argument is case sensitive. Do not use the set_tile function between start_image and end_image function calls.
start_list: Starts the processing of a list in the list box or in the pop-up list dialog box tile.
(start_list key [operation [index]])
The key argument is a string that specifies the dialog box tile. The key argument is case sensitive. The operation argument is an integer value whose meaning is summarized in the following table.
List box codes for start_list
Value : Description
1 : Change selected list contents
2 : Append new list entry
3 : Delete old list and create new list (the default)
The index argument is ignored unless the start_list call begins a change operation (1), in which case index indicates the list item to change by the subsequent add_list call. The index is zero based. If you don't specify operation, it defaults to 3 (create new list), and if you specify operation but not index, the index defaults to 0. Subsequent calls to add_list affect the list started by start_list until the application calls end_list. Do not use the set_tile function between start_list and end_list function calls.
strcase: Returns a string where all alphabetic characters have been converted to upper case or lower case.
(strcase string [which])
If which is omitted or evaluates to nil, all alphabetic characters in string are converted to upper case. If which is supplied and is not nil, all alphabetic characters in string are converted to lower case.
(strcase "Sample") returns "SAMPLE"
(strcase "Sample" T) returns "sample"
The strcase function will correctly handle case mapping of the currently configured character set.
strcat: Returns a string that is the concatenation of multiple strings.
(strcat string1 [string2]...)
(strcat "a" "bout") returns "about"
(strcat "a" "b" "c") returns "abc"
(strcat "a" "" "c") returns "ac"
strlen: Returns an integer that is the number of characters in a string.
(strlen [string]...)
If multiple string arguments are provided, it returns the sum of the lengths of all arguments. Omitting the arguments or entering an empty string returns 0 (zero).
(strlen "abcd") returns 4
(strlen "ab") returns 2
(strlen "one" "two" "four") returns 10
(strlen) returns 0
(strlen "") returns 0
subst: Searches a list for an old item and returns a copy of the list with a new item substituted in place of every occurrence of the old item.
(subst newitem olditem lst)
If olditem is not found in lst, subst returns lst unchanged.
(setq sample '(a b (c d) b))
(subst 'qq 'b sample): ;returns (A QQ (C D) QQ)
(subst 'qq 'z sample): ;returns (A B (C D) B)
(subst 'qq '(c d) sample): ;returns (A B QQ B)
(subst '(qq rr) '(c d) sample): returns (A B (QQ RR) B)
(subst '(qq rr) 'z sample): ;returns (A B (C D) B)
When used in conjunction with assoc, subst provides a convenient means of replacing the value associated with one key in an association list.
(setq who '((first john) (mid q) (last public)))
(setq old (assoc 'first who): sets old to (FIRST JOHN)
new '(first j): sets new to (FIRST J)
)
(subst new old who) returns ((FIRST J)(MID Q)(LAST PUBLIC))
substr: Returns a substring of a string.
(substr string start [length])
The substr function starts at the start character position of string and continues for length characters. If length is not specified, the substring continues to the end of string. The start and length arguments must be positive integers. The first character of string is character number 1. This differs from other functions that process elements of a list (like nth and ssname) that count the first element as 0.
(substr "abcde" 2): returns "bcde"
(substr "abcde" 2 1): returns "b"
(substr "abcde" 3 2): returns "cd"

T   tablet     tblnext     tblobjname     tblsearch     term_dialog     terpri     textbox     textpage     textscr     trace     trans     type  
tablet: Retrieves and sets digitizer (tablet) calibrations.
(tablet code [row1 row2 row3 direction])
Depending on the integer specified by code, tablet either retrieves the current digitizer calibration or sets the calibration. If code is 0, tablet returns the current calibration. If code is 1, it must be followed by the new calibration settings: row1, row2, row3, and direction.
Code: An integer. If the code you pass equals 0, tablet returns the current calibration; in this case, the remaining arguments must be omitted. If the code you pass equals 1, tablet sets the calibration according to the arguments that follow; in this case, you must provide the other arguments. row1, row2, row3 Three 3D points. These three arguments specify the three rows of the tablet's transformation matrix.
direction: One 3D point. This is the vector (expressed in the World Coordinate System, or WCS) that is normal to the plane that represents the surface of the tablet.
Note If the direction specified isn't normalized, tablet corrects it, so the direction it returns when you set the calibration may differ from the value you passed. In a similar way, the third element in row3 (Z) should always equal 1: tablet returns it as 1 even if the row3 in the list specified a different value. If tablet fails, it returns nil and sets the ERRNO system variable to a value that indicates the reason for the failure (Appendix D "AutoLISP Error Codes and Error Messages"). This can happen if the digitizer is not a tablet.
A very simple transformation that can be established with tablet is the identity transformation:
(tablet 1 '(1 0 0) '(0 1 0) '(0 0 1) '(0 0 1))
With this transformation in effect, AutoCAD will receive, effectively, raw digitizer coordinates from the tablet. For example, if you pick the point with digitizer coordinates (5000,15000), AutoCAD will see it as the point in your drawing with those same coordinates. The TABMODE system variable allows AutoLISP routines to toggle the tablet on and off.
tblnext: Finds the next item in a symbol table.
(tblnext table-name [rewind])
The table-name argument is a string the identifies the symbol table. Valid table-name values are "LAYER", "LTYPE", "VIEW", "STYLE", "BLOCK", "UCS", "APPID", "DIMSTYLE", and "VPORT". The string does not need to be upper case. Since the vports function returns current VPORT table information, it may be easier to use vports as opposed to tblnext to retrieve this information. When tblnext is used repeatedly, it normally returns the next entry in the specified table each time. The tblsearch function can set the next entry to be retrieved. However, if the rewind argument is present and evaluates to a non-nil value, the symbol table is rewound and the first entry in it is retrieved. If there are no more entries in the table, nil is returned. Deleted table entries are never returned. If an entry is found, it is returned as a list of dotted pairs of DXF-type codes and values.
(tblnext "layer" T): Retrieves first layer might return
((0 . "LAYER"): Symbol type
(2 . "0"): Symbol name
(70 . 0): Flags
(62 . 7): Color number, negative if off
(6 . "CONTINUOUS") Linetype name
)
Note that there is no -1 group. AutoCAD remembers the last entry returned from each table and returns the next one each time tblnext is called for that table. When you begin scanning a table, be sure to supply a non-nil second argument to rewind the table and to return the first entry. Entries retrieved from the block table include a -2 group with the entity name of the first entity in the block definition (if any). Thus, given a block called BOX,
(tblnext "block") Retrieves block definition might return
((0 . "BLOCK"): ;Symbol type
(2 . "BOX"): ;Symbol name
(70 . 0): ;;Flags
(10 9.0 2.0 0.0): ;Origin X,Y,Z
(-2 . ): First entity
)
The entity name in the -2 group is accepted by entget and entnext, but not by other entity access functions. For example, you cannot use ssadd to put it in a selection set. By providing the -2 group entity name to entnext, you can scan the entities comprising a block definition; entnext returns nil after the last entity in the block definition. If a block contains no entities, the -2 group returned by tblnext is the entity name of its endblk entity.
tblobjname: Returns the entity name of a specified symbol table entry.
(tblobjname table-name symbol)
The tblobjname function searches the symbol table, table-name, for the symbol name symbol and returns the entity name of that symbol table entry. The entity name returned by tblobjname can be used in entget and entmod operations.
tblsearch: Searches a symbol table for a symbol name.
(tblsearch table-name symbol [setnext])
The tblsearch function searches the symbol table, table-name, for the symbol name symbol. Both names are converted to upper case automatically. If tblsearch finds an entry for the given symbol name, it returns that entry in the format described for tblnext. If no such entry is found, it returns nil.
(tblsearch "style" "standard") Retrieves text style might return
((0 . "STYLE") Symbol name
(70 . 0): Flags
(40 . 0.0) Fixed height
(41 . 1.0) Width factor
(50 . 0.0) Obliquing angle
(71 . 0) Generation flags
(3 . "txt") Primary font file
(4 . "") Bigfont file
)
Normally, tblsearch has no effect on the order of entries retrieved by tblnext. However, if tblsearch is successful and the setnext argument is present and non-nil, the tblnext entry counter is adjusted so that the following tblnext call returns the entry after the one returned by this tblsearch call.
term_dialog: Terminates all current dialog boxes as if the user had canceled each of them.
(term_dialog)
If an application is terminated while any DCL files are open, AutoCAD automatically calls term_dialog. This function is used mainly for aborting nested dialog boxes. The term_dialog function always returns nil.
terpri: Prints a newline to the command line.
(terpri)
The terpri function is not used for file I/O. To write a newline to a file, use prin1, princ, or print.
textbox: Measures a specified text object, and returns the diagonal coordinates of a box that encloses the text.
(textbox elist)
The elist argument is an entity definition list in the form returned by entget. It must define a text object. If fields that define text parameters other than the text itself are omitted from elist, the current (or default) settings are used. If textbox is successful, it returns a list of two points; otherwise it returns nil. The minimum list accepted by textbox is that of the text itself.
(textbox '((1 . "Hello world."))) might return ((0.0 0.0 0.0) (0.8 0.2 0.0))
In this case, textbox would use the current defaults for text to supply the remaining parameters. The points returned by textbox describe the bounding box of the text object as if its insertion point is located at (0,0,0) and its rotation angle is 0. The first list returned is generally the point (0.0 0.0 0.0) unless the text object is oblique or vertical, or it contains letters with descenders (such as g and p). The value of the first point list specifies the offset from the text insertion point to the lower-left corner of the smallest rectangle enclosing the text. The second point list specifies the upper-right corner of that box. Regardless of the orientation of the text being measured, the point list returned always describes the bottom-left and upper-right corners of this bounding box.
textpage: Switches from the graphics screen to the text screen.
(textpage)
The textpage function is equivalent to textscr. This function always returns nil.
textscr: Switches from the graphics screen to the text screen (like the AutoCAD Flip Screen function key F2)
(textscr)
The textscr function always returns nil.
trace: Aids in AutoLISP debugging.
(trace function...)
The trace function sets the trace flag for the specified functions. Each time a specified function is evaluated, a trace display appears showing the entry of the function (indented to the level of calling depth) and prints the result of the function.
(trace my-func) returns MY-FUNC
and sets the trace flag for function MY-FUNC. The trace function returns the last function name passed to it. (See also the untrace function)
trans: Translates a point (or a displacement) from one coordinate system to another.
(trans pt from to [disp])
The pt argument is a list of three reals that can be interpreted as either a 3D point or a 3D displacement (vector). The from argument indicates the coordinate system in which pt is expressed, and to specifies the coordinate system of the returned point. The optional disp argument, if present and non-nil, specifies that pt is to be treated as a 3D displacement rather than as a point. The from and to arguments can be an integer code (as specified in the following table), an entity name, or a 3D extrusion vector.
Coordinate system codes
Code : Coordinate system
0 : World (WCS)
1 : User (current UCS)
2 : Display: DCS of current viewport when used with code 0 or 1
;; DCS of current model space viewport when used with code 3
3 : Paper space DCS (used only with code 2)
If you use an entity name for the from or to arguments it must be passed as returned by the entnext, entlast, entsel, nentsel, and ssname functions. This lets you translate a point to and from the Object Coordinate System (OCS) of a particular object. (For some objects, the OCS is equivalent to the WCS; for these objects, conversion between OCS and WCS is a null operation.) A 3D extrusion vector (a list of three reals) is another method of converting to and from an object's OCS. However, this does not work for those objects whose OCS is equivalent to the WCS. The trans function returns a 3D point (or displacement) in the requested to coordinate system. For example, given a UCS that is rotated 90 degrees counterclockwise around the World Z axis,
(trans '(1.0 2.0 3.0) 0 1) returns (2.0 -1.0 3.0)
(trans '(1.0 2.0 3.0) 1 0) returns (-2.0 1.0 3.0)
To draw a line from the insertion point of a piece of text (without using Osnap), you convert the text object's insertion point from the text object's OCS to the UCS.
(trans text-insert-point text-ename 1)
You can then pass the result to the From point prompt. Conversely, you must convert point (or displacement) values to their destination OCS before feeding them to entmod. For example, if you want to move a circle (without using the MOVE command) by the UCS-relative offset (1,2,3), you need to convert the displacement from the UCS to the circle's OCS:
(trans '(1 2 3) 1 circle-ename)
Then you add the resulting displacement to the circle's center point. For example, if you have a point entered by the user and want to find out which end of a line it looks closer to, you convert the user's point from the UCS to the DCS.
(trans user-point 1 2)
Then you convert each of the line's endpoints from the OCS to the DCS.
(trans endpoint line-ename 2)
From there you can compute the distance between the user's point and each endpoint of the line (ignoring the Z coordinates) to determine which end looks closer. The trans function can also transform 2D points. It does this by filling in the Z coordinate with an appropriate value. The Z component used depends on the from coordinate system that was specified and on whether the value is to be converted as a point or as a displacement. If the value is to be converted as a displacement, the Z value is always 0.0; if the value is to be converted as a point, the filled-in Z value is determined as shown in the following table.
Converted 2D point Z values
From;Filled-in Z value
WCS : 0.0
UCS : Current elevation
OCS : 0.0
DCS : Projected to the current construction plane(UCS XY plane + current elevation)
PSDCS : Projected to the current construction plane(UCS XY plane + current elevation)
type: Returns the type of a specified item.
(type item)
The types are returned as one of the atoms shown in the following table:
Symbol types: Type Description
REAL Floating-point numbers SUBR Internal functions
FILE File descriptors EXSUBR External functions (ARX)
STR Strings PICKSET Selection sets
INT Integers ENAME Entity names
SYM Symbols PAGETB Function paging table
LIST Lists (and user functions)
Items that evaluate to nil (such as an unassigned symbol) return nil.
For example, given the assignments
(setq a 123 r 3.45 s "Hello!" x '(a b c))
(setq f (open "name" "r"))
then
(type 'a) returns SYM
(type a) returns INT
(type f) returns FILE
(type r) returns REAL
(type s) returns STR
(type x) returns LIST
(type +) returns SUBR
(type nil) returns nil
The following example uses the type function:
(defun isint (a)
(if (= (type a) 'INT) is TYPE integer?
T yes, return T
nil no, return nil
)
)

U   unload_dialog     untrace  
unload_dialog: Unloads a DCL file.
(unload_dialog dcl_id)
Unloads the DCL file associated with dcl_id (which was obtained from a previous new_dialog call). Always returns nil.
untrace: Clears the trace flag for the specified functions.
(untrace function...)
Returns the last function name. The following code clears the trace flag for function MY-FUNC
:
(untrace my-func): returns MY-FUNC
(See also the trace function)

V   vector_image     ver     vports  
vector_image: Draws a vector in the currently active dialog box image.
(vector_image x1 y1 x2 y2 color)
This function draws a vector in the currently active dialog box image (opened by start_image) from the point (x1,y1) to (x2,y2). The color parameter is an AutoCAD color number or one of the logical color numbers shown in the following table.
Symbolic names for the color attribute
Color : number : ADI mnemonic Description
-2 : BGLCOLOR: Current background of the AutoCAD graphics screen
-15 : DBGLCOLOR: Current dialog box background color
-16 : DFGLCOLOR: Current dialog box foreground color (for text)
-18 : LINELCOLOR: Current dialog box line color
The origin (0,0) is the upper-left corner of the image. You can obtain the coordinates of the lower-right corner by calling the dimension functions (dimx_tile and dimy_tile).
ver: Returns a string that contains the current AutoLISP version number.
(ver)
The ver function should be used (with equal) to check the compatibility of programs. The string takes the form "AutoLISP Release X.X (nn)" where X.X is the current version number and nn is a two letter language description.
(ver) might return "AutoLISP Release 14.0 (en)"
Examples of the two letter language descriptions are as follows: (en) US/UK;(es) Spanish;(fr) French; (de) German;(it) Italian
vports: Returns a list of viewport descriptors for the current viewport configuration
(vports)
Each viewport descriptor is a list consisting of the viewport identification number and the coordinates of the viewport's lower-left and upper-right corners. If the AutoCAD system variable TILEMODE is set to 1 (on), the returned list describes the viewport configuration created with the AutoCAD VPORTS command. The corners of the viewports are expressed in values between 0.0 and 1.0, with (0.0, 0.0) representing the lower-left corner of the display screen's graphics area, and (1.0, 1.0) the upper-right corner. If TILEMODE is 0 (off), the returned list describes the viewport objects created with the MVIEW command. The viewport object corners are expressed in paper space coordinates. Viewport number 1 is always paper space when TILEMODE is off. For example, given a single-viewport configuration with TILEMODE on, the vports function might return this:
((1 (0.0 0.0) (1.0 1.0)))
Similarly, given four equal-sized viewports located in the four corners of the screen when TILEMODE is on, the vports function might return this:
(;(5 (0.5 0.0) (1.0 0.5))
;(2 (0.5 0.5) (1.0 1.0))
;(3 (0.0 0.5) (0.5 1.0))
;(4 (0.0 0.0) (0.5 0.5)) )
The current viewport's descriptor is always first in the list. In the previous example, viewport number 5 is the current viewport.

W   wcmatch     while     write-char     write-line  
wcmatch: Performs a wild-card pattern match on a string.
(wcmatch string pattern)
The wcmatch function compares the string to the pattern to see if they match. If so, T is returned; otherwise, nil is returned. Both string and pattern can be either a quoted string or a variable. The pattern can contain the wild-card pattern-matching characters shown in the following table. Only the first 500 characters (approximately) of the string and pattern are compared; anything beyond that is ignored.
Wild-card characters
Character;Definition
# (pound) : Matches any single numeric digit
@ (at) : : Matches any single alphabetic character
. (period) : Matches any single nonalphanumeric character * (asterisk) : Matches any character sequence, including an empty one, and it can be used anywhere in the search pattern: at the beginning, middle, or end
? (question mark) : Matches any single character
~ (tilde) : If it is the first character in the pattern, it matches anything except the pattern
[...]: : Matches any one of the characters enclosed
[~...]: : Matches any single character not enclosed
- (hyphen) : Used inside brackets to specify a range for a single character
, (comma) : Separates two patterns
` (reverse quote) : Escapes special characters (reads next character literally)
(wcmatch "Name" "N*") returns T
This tests the string Name to see if it begins with the character N. You can use commas in a pattern to enter more than one pattern condition. This example performs three comparisons:
(wcmatch "Name" "???,~*m*,N*") returns T
If any of the three pattern conditions is met, wcmatch returns T. In this case the tests are these: Name has three characters (false). Name does not contain an m (false); and Name begins with N (true). At least one condition was met, so this expression returns T. The comparison is case sensitive, so upper- and lowercase characters must match. It is valid to use variables and values returned from AutoLISP functions for string and pattern values. To test for a wild-card character in a string, you can use the single reversequote character (`) to escape the character. Escape means that the character following the single reverse quote is not read as a wildcard character; it is compared at its face value. For example, to search for a comma anywhere in the string Name, enter this:
(wcmatch "Name" "*`,*") returns nil
Note Because other wild-card characters might be added in future releases of AutoLISP, it is a good idea to escape all nonalphanumeric characters in the pattern to ensure upward compatibility. Both the C and AutoLISP programming languages use the backslash (\) as an escape character, so you need two backslashes (\\) to produce one backslash in a string. To test for a backslash character anywhere in Name, you enter this:
(wcmatch "Name" "*`\\*") returns nil
All characters enclosed in brackets ([ . . . ]) are read literally, so there is no need to escape them, with the following exceptions: the tilde character (~) is read literally only when it is not the first bracketed character (as in "[A~BC]"); otherwise it is read as the negation character, meaning that wcmatch should match all characters except those following the tilde (as in "[~ABC]"). The dash character (-) is read literally only when it is the first or last bracketed character (as in "[-ABC]" or "[ABC-]") or when it follows a leading tilde (as in "[~-ABC]"). Otherwise, the dash character (-) is used within brackets to specify a range of values for a specific character. The range works only for single characters, so "STR[1-38]" matches STR1, STR2, STR3, and STR8, and "[A-Z]" matches any single uppercase letter. The closing bracket character ("]") is also read literally if it is the first bracketed character or if it follows a leading tilde (as in "[ ]ABC]" or "[~]ABC]").
while: Evaluates a test expression, and if it is not nil, evaluates other expressions; repeats this process until the test expression evaluates to nil
(while testexpr expr...)
The while function continues until testexpr is nil. It then returns the most recent value of the last expr. The following code calls user function SOME-FUNC ten times, with test set to 1 through 10. It then returns 11, which is the value of the last expression evaluated.
(setq test 1)
(while (<= test 10)
(some-func test)
(setq test (1+ test))
)
write-char: Writes one character to the screen or to an open file.
(write-char num [file-desc])
The num argument is the decimal ASCII code for the character to be written and is also the value returned by write-char.
(write-char 67) returns 67 and writes the letter C on the screen. Assuming that f is the descriptor for an open file:
(write-char 67 f) returns 67 and writes the letter C to that file.
The various operating systems on which AutoCAD runs separate conventions to signal the end of a line in an ASCII text file. UNIX systems, for example, use a single newline character (LF, ASCII code 10), whereas DOS systems use a pair of characters (CR/LF, ASCII codes 13 and 10) for the same purpose. To facilitate development of AutoLISP programs, write-char translates a newline character (ASCII code 10) into the end-of-line character (or character sequence) used by the operating system that you're currently using. Thus, on a DOS system,
(write-char 10 f) returns 10 but writes the character sequence CR/LF (ASCII codes 13 and 10) to the file. write-char cannot write a NUL character (ASCII code 0) to a file.
write-line: Writes a string to the screen or to an open file.
(write-line string [file-desc])
It returns string quoted in the normal manner but omits the quotes when writing to the file. For example, assuming that f is a valid open file descriptor, (write-line "Test" f) writes Test and returns "Test"

X   xdroom     xdsize     xload     xunload  
xdroom: Returns the amount of extended data (Xdata) space that is available for an object (entity).
(xdroom ename)
If unsuccessful, xdroom returns nil. Because there is a limit (currently, 16 kilobytes) on the amount of extended data that can be assigned to an entity definition, and because multiple applications can append extended data to the same entity, this function is provided so that an application can verify that there is room for the extended data that it will append. It can be called in conjunction with xdsize, which returns the size of an extended data list. Here is an example that looks up the available space for extended data of a viewport object. Assuming that the variable vpname contains the name of a viewport object,
(xdroom vpname): returns 16162
In this example, 16,162 bytes of the original 16,383 bytes of extended data space are available, meaning that 221 bytes are used. You can determine the amount of available data space by using the xdsize function.
xdsize: Returns the size (in bytes) that a list occupies when it is linked to an object (entity) as extended data.
(xdsize lst)
If unsuccessful, xdsize returns nil. The lst argument must be a valid list of extended data that contain an application name previously registered with the use of the regapp function. Brace fields (group code 1002) must be balanced. An invalid lst generates an error and places the appropriate error code in the ERRNO variable. If the extended data contains an unregistered application name, you see this error message (assuming that CMDECHO is on): Invalid application name in 1001 group. The lst can start with a -3 group code (the extended data sentinel), but it is not required. Because extended data can contain information from multiple applications, the list must have a set of enclosing parentheses.
(-3 ("MYAPP" (1000 . "SUITOFARMOR")
(1002 . "{")
(1040 . 0.0)
(1040 . 1.0)
(1002 . "}")
)
)
Here is the same example without the -3 group code. This list is just the cdr of the first example, but it is important that the enclosing parentheses are included:
( ("MYAPP" (1000 . "SUITOFARMOR")
(1002 . "{")
(1040 . 0.0)
(1040 . 1.0)
(1002 . "}")
)
)
xload: Loads an ADS application.
(xload application [onfailure])
The application argument is entered as a quoted string or as a variable that contains the name of an executable file. At the time the file is loaded, it is verified to be a valid ADS application. Also, the version of the ADS program, ADS itself, and the version of AutoLISP that is running are checked for compatibility. If the xload operation fails, it normally causes an AutoLISP error. However, if the onfailure argument is supplied, xload returns the value of this argument upon failure instead of an error message. If the application is successfully loaded, the application name is returned.
(xload "/myapps/xapp") if successful, returns "/myapps/xapp"
If you attempt to load an application that is already loaded, xload issues the message Application "application" already loaded. and returns the application name. You may want to check the currently loaded ADS applications with the ads function before using xload.
xunload: Unloads an ADS application.
(xunload application [onfailure])
If the application is successfully unloaded, the application name is returned; otherwise, an error message is issued. Enter application as a quoted string or as a variable containing the name of an application that was loaded with the xload function. The application name must be entered exactly as it was entered for the xload function. If a path (directory name) was entered for the application in xload, it can be omitted in the xunload function. For example, the following function will unload the previous application loaded by the xload function:
(xunload "ame") if successful, returns "ame"
If the xunload operation fails, it normally causes an AutoLISP error. However, if the onfailure argument is supplied, xunload returns the value of this argument upon failure instead of issuing an error message. This feature of xunload is similar to that in the xload function.

Z   zerop  
zerop: Verifies that a number evaluates to zero.
(zerop number)
Returns T if number evaluates to zero, returns nil otherwise.
(zerop 0): returns T
(zerop 0.0): returns T
(zerop 0.0001): returns nil

backBack top