Architectural and Engineering Computer Aided Design
Austin Community College
DFTG 2436: CAD Programming
AutoLISP Function Compendium


Table of Contents
Function-Handling Functions
List Manipulation Functions
Manipulating System Variables
Arithmetic Functions
GETxxx Functions
Distances and Angles
Printing Functions
String Functions
Symbol-Handling Functions
Numerical Comparison Functions
Type Conversion Functions

Conditional Functions
Looping Functions
Entity Manipulation Functions
Selection Set Functions
Symbol Table Access Functions
File Input/Output Functions
Programmable Dialog Box Functions
Opening and Closing Dialog Boxes
Handling Tiles and Attributes
Handling List Boxes and Pop-Up Lists
Handling Image Tiles
 
Function-Handling Functions Top
LOAD 2-6 (load FILENAME [ONFAILURE])
Causes AutoLISP to read the program file specified by string argument FILENAME, check for syntax errors, and evaluate the expressions in the file; if successful, returns the value of the final expression within the file; if not, returns string in ONFAILURE (if included).
DEFUN 2-18 (defun SYMBOL ARGUMENT-LIST EXPRESSION...)
Defines a function named SYMBOL, with any arguments defined in ARGUMENT-LIST, containing some number of expressions; returns the value of the last expression evaluated.
SETQ 1-12 (setq SYMBOL1 VALUE1 [SYMBOL2 VALUE2] ...)
Assigns VALUE1 to SYMBOL1, VALUE2 to SYMBOL2, etc.; returns the last value assigned.
QUOTE 2-10 (quote EXPRESSION)
Returns an expression literally, without evaluating it.
PROGN 8-10 (progn [EXPR] ...)

Evaluates each expression sequentially, and returns the value of the last expression.
COMMAND 2-14 (command [ARGUMENTS] ...)

Executes one or more AutoCAD commands as specified by ARGUMENTS.
List Manipulation Functions Top
CAR 3-5 (car LIST)
Returns the first element of LIST.
CDR 3-6 (cdr LIST)
Returns a list containing all but the first element of LIST.
CADR 3-9 (cadr LIST)
Returns the second element of LIST.
CADDR 3-10 (caddr LIST)
Returns the third element of LIST.
All concatenations of CAR and CDR supported by AutoLISP:
caaaar cadaar cdaaar cddaar
caaadr cadadr cdaadr cddadr
caaar cadar cdaar cddar
caadar caddar cdadar cdddar
caaddr cadddr cdaddr cdddddr
caadr caddr cdadr cdddr
caar cadr cdar cddr
NTH 10-9 (nth N LIST)
Returns the Nth element (specified by the integer N argument) of the list specified by LIST; the first element is number 0.
LIST 3-2 (list EXPR...)
Combines any number of expressions into a list.
APPEND 9-5 (append LIST ...)
Combines any number of lists into a single list.
ASSOC 10-3 (assoc ITEM ALIST)
Searches an association list for the ITEM element and returns that association list entry.
CONS 10-4 (cons NEW-FIRST-ELEMENT LIST)
(cons NEW-FIRST-ELEMENT ATOM)
Basic list constructor; the first format adds a new element to the beginning of a list; the second format creates a dotted pair.
LAST 3-15 (last LIST)
Returns the last element of LIST.
LENGTH 3-15 (length LIST)
Returns the number of elements contained in LIST.
SUBST 13-20 (subst NEWITEM OLDITEM LIST)
Searches a list for OLDITEM and returns a copy of the LIST with NEWITEM substituted for every occurrence of OLDITEM.
Manipulating System Variables Top
GETVAR 4-10 (getvar VARNAME)
Returns the value of the AutoCAD system variable specified in string VARNAME.
SETVAR 4-10 (setvar VARNAME VALUE)
Sets AutoCAD system variable in string VARNAME to value specified by VALUE.
Arithmetic Functions Top
+ (Addition) 1-5 (+ [NUM NUM] ...)
Accepts one or more numbers and returns the sum of all the numbers.
- (Subtraction) 1-6 (- [NUM NUM] ...)
Subtracts the sum of the second through the last numbers from the first number and returns the difference.
* (Multiplication) 1-6 (* [NUM NUM] ...)
Multiplies all numbers and returns the product.
/ (Division) 1-7 (/ [NUM NUM] ...)
Divides the first number by the product of the second through the last numbers and returns the quotient.
1+ (Increment) 9-6 (1+ NUM)
Returns the argument increased by 1 (incremented).
1- (Decrement) 9-6 (1- NUM)
Returns the argument decreased by 1 (decremented).
FIX 6-2 (fix NUM)
Returns the conversion of a real into the nearest smaller integer.
FLOAT 6-2 (float NUM)
Returns the conversion of a number into a real.
REM 6-4 (rem NUM1 NUM2...)
Divides the first number by the second, and returns the remainder.
EXPT 6-9 (expt BASE POWER)
Returns a number that is the result of raising the BASE to the specified POWER.
SIN 6-6 (sin ANGLE)
Returns a real number that is the sine of ANGLE expressed in radians.
COS 6-7 (cos ANGLE)
Returns a real number that is the cosine of ANGLE expressed in radians.
ATAN 6-7 (atan NUM1 [NUM2])
Returns a real number in radians that is the arctangent of NUM1, or of NUM1/NUM2.
GETxxx Functions Top
GETPOINT 3-3 (getpoint [PT] [PROMPT])
Pauses for user to pick a point; displays rubberband from PT argument (if included); displays PROMPT string (if included); returns a list containing X, Y, and Z coordinates of point picked.
GETCORNER 3-13 (getcorner PT [PROMPT])
Pauses for user input of a rectangle’s second corner; the first corner is specified by the required PT argument; displays the PROMPT string (if included).
GETINT 4-2 (getint [PROMPT])
Pauses for user input of an integer; returns that integer; displays PROMPT string (if included).
GETREAL 4-3 (getreal [PROMPT})
Pauses for user input of a real number; returns that real number; displays PROMPT string, (if included).
GETSTRING 4-5 (getstring [CR] [PROMPT])
Pauses for user input of a string, and returns that string; if included and non-nil, the CR argument allows spaces in the returned string; displays PROMPT string, if included.
INITGET 4-7 (initget [BITS] [STRING])
Establishes allowable input options and key words for use by the next user-input function call; always returns nil; STRING specifies allowable keyword responses for next GETKWORD function call.
Bit Description
1 Value must be supplied.
2 Response cannot be zero.
4 Response cannot be negative.
8 Limits are ignored for point picks even if LIMCHECK is On.
16 Do not use.
32 Use dashed lines for rubberband line or box
64 Ignores Z coordinate of 3D input; returns 2D distance
128 Allows arbitrary input as if it is a keyword (other control bits honored first); takes precedence over bit 0; if mode 129 (128 + 1) is set and user presses Enter, a null string is returned.
GETKWORD 4-8 (getkword [PROMPT])
Pauses for user input of a key word specified in previous call to INITGET; returns that key word; displays PROMPT string, if included.
GETANGLE 5-6 (getangle [PT] [PROMPT])
Pauses for user input of an angle, and returns that angle in radians; measures angles with the zero-radian direction set by the ANGBASE system variable, with angles increasing in the counterclockwise direction.
GETORIENT 5-8 (getorient [PT] [PROMPT])
Pauses for user input of an angle, and returns that angle in radians; the angle value returned is unaffected by the settings of ANGBASE and ANGDIR.
GETDIST 5-10 (getdist [PT] [PROMPT])
Pauses for user input of a distance. The user can specify the distance by entering a number, or by selecting two points (or just the second point if the PT argument is included).
Distances and Angles Top
ANGLE 5-4 (angle PT1 PT2)
Returns the angle in radians of a line defined by endpoints PT1 and PT2; the line is measured from the X axis of the current construction plane.
DISTANCE 5-5 (distance PT1 PT2)
Returns the 3D distance between the two points specified by PT1 and PT2.
POLAR 5-5 (polar PT ANGLE DISTANCE)
Returns a point list containing the 3D point at an angle specified by ANGLE and a distance specified by DISTANCE from the point specified by PT.
OSNAP 5-13 (osnap PT MODE-STRING)
Returns a 3D point that is the result of applying the Object Snap mode(s) specified by the string MODE-STRING to the point specified by PT.
INTERS 5-17 (inters PT1 PT2 PT3 PT4 [ONSEG])
Finds the intersection of the line specified by points PT1 and PT2 and the line specified by PT3 and PT4; if ONSEG is included and is nil, the lines 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 lines; if ONSEG is omitted or is included and non-nil, the intersection point must lie on both lines; returns a point list if intersection is found, nil if not.
Printing Functions Top
PROMPT 2-13 (prompt MESSAGE)
Prints string MESSAGE to the command line.
PRIN1 7-13 (prin1 [EXPR [FILE-DESC]])
Prints a string to the command line or writes it to the open file represented by FILE-DESC.
PRINC 7-14 (princ [EXPR [FILE-DESC]])
Prints a string to the command line or writes it to the open file represented by FILE-DESC.
PRINT 7-18 (print [EXPR [FILE-DESC]])
Prints a string to the command line or writes it to the open file represented by FILE-DESC.
String Functions Top
STRCASE 7-19 (strcase STRING [WHICH])
Returns a string with all alphabetic characters converted to uppercase; if WHICH is supplied and is not nil, all alphabetic characters are converted to lowercase.
STRCAT 7-19 (strcat STRING1 [STRING2] ...)
Returns a string that is a concatenation of all the argument strings.
STRLEN 7-21 (strlen [STRING] ...)
Returns an integer that is the total number of characters in all strings passed to it.
SUBSTR 7-22 (substr STRING START [LENGTH])
Returns a substring of a string.
Symbol-Handling Functions Top
EQ 8-3 (eq EXPR1 EXPR2)
Determines whether two expressions are identical, that is, whether they point to the same address in memory.
EQUAL 8-3 (equal EXPR1 EXPR2 [FUZZ])
Determines whether two expressions evaluate to the same thing; the FUZZ argument determines how much they can differ and still be considered equal.
ATOM 8-5 (atom ITEM)
Returns T if ITEM is not a list, and returns nil otherwise.
LISTP 8-6 (listp ITEM)
Returns T if ITEM is a list, and returns nil otherwise.
NUMBERP 8-6 (numberp ITEM)
Returns T if ITEM is real or an integer, and returns nil otherwise.
MINUSP 8-6 (minusp NUM)
Returns T if NUM is negative, and returns nil otherwise.
ZEROP 8-7 (zerop NUM)
Returns T if NUM evaluates to zero, returns nil otherwise.
NULL 8-7 (null ITEM)
Returns T if ITEM is bound to nil, and returns >nil otherwise.
AND 8-11 (and EXPR...)
Returns T if all expressions arguments evaluate to non-nil; if any of the expression arguments evaluates to nil, this function ceases further evaluation and returns nil.
OR 8-12 (or EXPR...)
Returns T as soon as it encounters an expression argument that evaluates to non-nil; otherwise, it returns nil.
NOT 8-12 (not ITEM)
Returns T if ITEM evaluates to nil, and returns nil otherwise.
TYPE 8-17 (type ITEM)
Returns the type of ITEM (REAL, FILE, STR, INT, SYM, LIST, ENAME, SUBR, EXSUBR, PICKSET, or PAGETB).
Numerical Comparison Functions Top
= (equal to) 8-2 (= NUMSTR [NUMSTR] ...)
Returns T if all arguments are numerically equal, and returns nil otherwise.
/= (not equal to) 8-4 (/= NUMSTR [NUMSTR] ...)
Returns T if all the arguments are not numerically equal, and nil if all arguments are numerically equal.
< (less than) 8-4 (< NUMSTR [NUMSTR] ...)
Returns T if each argument is numerically less than the next argument, and returns nil otherwise.
> (greater than) 8-4 (> NUMSTR [NUMSTR] ...)
Returns T if each argument is numerically greater than the next argument, and returns nil otherwise.
<= (less than or equal to) 8-4 (<= NUMSTR [NUMSTR] ...)
Returns T if each argument is numerically less than or equal to the next argument, and returns nil otherwise.
>= (greater than or equal to) 8-4 (>= NUMSTR [NUMSTR] ...)
Returns T if each argument is numerically greater than or equal to the next argument, and returns nil otherwise.
Type Conversion Functions Top
CVUNIT 5-3 (cvunit VALUE FROM TO)
If ACAD.UNT file is found, converts VALUE from units specified by string FROM to units specified by string TO.
DTR (dtr D)
Converts degrees to radians; returns value in radians.
RTD (rtd R)
Converts radians to degrees; returns value in degrees.
ATOF 7-2 (atof STRING)
Returns the conversion of a string into a real.
ATOI 7-4 (atoi STRING)
Returns the conversion of a string into an integer.
RTOS 7-4 (rtos NUMBER [MODE [PRECISION]])
Converts a number into a string.
ITOA 7-6 (itoa INT)
Returns the conversion of an integer into a string.
ASCII 7-9 (ascii STRING)
Returns the conversion of the first character of STRING into its ASCII character code (a decimal integer).
CHR 7-10 (chr INTEGER)
Returns the conversion of INTEGER representing an ASCII character code into a single-character string.
Conditional Functions Top
IF 8-8 (if TESTEXPR THENEXPR [ELSEEXPR])
If TESTEXPR evaluates to a non-nil value, THENEXPR is evaluated, otherwise ELSEEXPR (if present) is evaluated. If TESTEXPR evaluates to nil, ELSEEXPR (if present) is evaluated. Returns the value of the evaluated expression, or, if TESTEXPR evaluates to nil and ELSEEXPR is missing, returns nil.
COND 8-19 (cond (TEST1 ACTION1 ...) ...)
Evaluates the test expressions in order until one returns a non-nil value, then evaluates the ACTION expression for the test that succeeded, and returns the value of the ACTION. If no ACTION is specified, the value of the TEST expression is returned.
Looping Functions Top
REPEAT 9-2 (repeat INT EXPR ...)
Evaluates each included expression INT number of times, and returns the value of the last expression.
WHILE 9-3 (while TEXTEXPR EXPR ...)
If TESTEXPR, evaluates to a non-nil value, the included expressions are evaluated; repeats until the test expression evaluates to nil.
FOREACH 9-8 (foreach NAME LIST EXPR ...)
Evaluates expressions for all members of a list. Assigns each element of the list to NAME, one at a time, and evaluates the expressions in the loop for each value of NAME.
Entity Manipulation Functions Top
ENTNEXT 13-2 (entnext [ENAME])
Returns the ENAME of the next non-deleted entity in the drawing database. If the ENAME argument is included, it returns the ENAME of the next non-deleted entity following the record with the name specified by the ENAME argument.
ENTGET 13-4 (entget ENAME [APPLIST])
Returns an association list representing the definition record of entity ENAME.
ENTLAST 13-10 (entlast)
Returns the ENAME of the last non-deleted main entity in a drawing; usually used to access an entity that has just been created.
ENTSEL 13-11 (entsel [PROMPT])
Prompts the user to select a single object by specifying a point; returns a list containing the ENAME of the object and a point list representing the point picked. If the optional PROMPT is not included, prompts the user with the Select objects: prompt. For complex entities, the function returns the ENAME of the main entity record; it does not provide subentity access.
ENTMOD 13-21 (entmod ELIST)
Modifies the definition record of an entity. You must first retrieve the record into a variable with ENTGET, then call SUBST to replace values in the variable, then call ENTMOD to write the value of the variable back to the database and update the display (for non-complex entities).
ENTUPD 13-22 (entupd ENAME)
Updates the screen display of a complex entity that has been modified by ENTMOD. First retrieve the record for the subentity with ENTGET, then call SUBST to replace the desired sublist(s), then call ENTMOD to replace the subentity record in the database, then call ENTUPD to update the screen.
ENTMAKE 13-25 (entmake [ELIST])
Creates a new entity in the drawing. All required sublists for the given entity must be included. The first or second sublist in ELIST must be the entity type (group code 0); other sublists can be in any order. Default values are assumed for optional fields that are omitted from ELIST.
ENTDEL 13-12 (entdel ENAME)
Deletes the entity with name ENAME or undeletes entity ENAME that was previously deleted in the current editing session.
NENTSEL 13-12 (nentsel [PROMPT])
Prompts the user to select an entity by specifying a point; provides access to a subentity record within a complex entity. Like ENTSEL, returns a list containing the ENAME of the object and a point list representing the point picked.
HANDENT 13-10 (handent HANDLE)
Returns the entity name of the entity specified by HANDLE.
Selection Set Functions Top
SSGET 12-2 (ssget [MODE] [P1 [P2]] [PLIST] [FILTER-LIST])
Prompts the user to select entities, and returns a selection set consisting of the ENAMEs of all the entities selected.
SSNAME 12-22 (ssname SS INDEX)
Returns the entity name of the indexed element of a selection set; the first element is 0.
SSLENGTH 12-21 (sslength SS)
Returns an integer containing the number of entities in the specified selection set.
SSADD 12-25 (ssadd [ENAME] [SS])
Adds an entity to a selection set. If called with no arguments, creates a new empty selection set. If called with only the ENAME argument, it creates a selection set containing only that entity name. If called with the ENAME and SS arguments, it adds the entity name ENAME to selection set SS. SSADD always returns the new or modified selection set. Therefore, it is not necessary to nest the SSADD expression in a SETQ.
SSDEL 12-28 (ssdel ENAME SS)
Deletes entity ENAME from selection set SS. The specified selection set is returned, minus the entity specified by ENAME. Therefore, it is not necessary to nest SSDEL in a SETQ.
SSMEMB 12-29 (ssmemb ENAME SS)
Tests whether entity ENAME is in selection set SS; if so, returns the entity name; if not, returns nil.
Symbol Table Access Functions Top
TBLNEXT 15-2 (tblnext TABLE-NAME [REWIND])
Finds the next item in the specified symbol table; if REWIND is included and is non-nil, the first entry in the symbol table is returned. The returned entry is formatted as an association list.
TBLSEARCH 15-9 (tblsearch TABLE-NAME SYMBOL [SETNEXT])
Searches the specified symbol table and returns the entry named by SYMBOL. If included and non-nil, SETNEXT sets the table pointer to the entry following the returned entry for a subsequent call to ENTNEXT.
TBLOBJNAME 15-11 (tblobjname TABLE-NAME SYMBOL)
Returns the entity name of a specified symbol table entry.
WCMATCH 15-16 (wcmatch STRING PATTERN)
Wild card match; compares STRING to PATTERN; returns T if they match, nil otherwise.
File Input/Output Functions Top
FINDFILE 14-2 (findfile FILENAME)
Searches the AutoCAD library path for the specified file.
OPEN 14-4 (open FILENAME MODE)
Opens a file for access by the AutoLISP I/O functions; MODE specifies the access type: "r" to read, "w" to write; "a" to append.
CLOSE 14-6 (close FILE-DESC)
Closes an open file; FILE-DESC is the handle returned by the OPEN function.
READ-LINE 14-5 (read-line [FILE-DESC])
Reads a string from the keyboard or a line from the file represented by FILE-DESC, if the file has been opened for reading.
READ-CHAR 14-11 (read-char [FILE-DESC])
Returns the decimal ASCII code representing the character read from the keyboard input buffer or from the file represented by FILE-DESK, if the file has been opened for reading.
WRITE-LINE 14-7 (write-line STRING [FILE-DESC])
Writes STRING to the Command window or to the file represented by FILE-DESC, if that file has been opened for writing or appending.
WRITE-CHAR 14-12 (write-char NUM [FILE-DESC])
Writes the ASCII character specified by decimal integer NUM to the Command window or to the file represented by FILE-DESC, if the file has been opened for writing or appending.
GETFILED 14-3 (getfiled TITLE DEFAULT EXT FLAGS)
Prompts the user to select a filename using the standard AutoCAD file selection dialog box. The TITLE argument specifies a label for the dialog. DEFAULT specifies a filename to display in the Filename edit box, while EXT is the default filename extension. FLAGS controls the behavior of the dialog, as shown in the following table.
Value Meaning
1 Indicates a request for a new file to be created
2 Disables the "Type it" button
4 Lets the user enter an arbitrary filename extension.
8 Performs a library search for the filename entered.
Programmable Dialog Box Functions Top
The programmable dialog box functions consist of functions for opening and closing dialog boxes, handling tiles and attributes, handling list boxes and pop-up lists, handling image tiles, and handling application-specific data.
Opening and Closing Dialog Boxes Top
DONE_DIALOG 18-4 (done_dialog [STATUS])
Terminates a dialog box. If included, the optional STATUS argument lets you return a value other than 1 (accept) or 0 (cancel) to the calling application.
LOAD_DIALOG 18-2 >(load_dialog DCLFILE)
Loads the DCL file specified by the DCLFILE string argument into memory; similar to loading an AutoLISP file.
NEW_DIALOG 18-3 new_dialog DLGNAME DCL_ID [ACTION [SCREEN-PT]])
Activates the dialog specified by DLGNAME and DCL_ID (returned by a prior call to LOAD_DIALOG); can also specify a default action that applies to all tiles that do not have an action specified.
START_DIALOG 18-3 (start_dialog)
Displays the current dialog box (defined by the preceding call to NEW_DIALOG) and begins accepting user input.
TERM_DIALOG 18-4 (term_dialog)
Terminates all currently active dialog boxes as if the user had cancelled each of them.
UNLOAD_DIALOG 18-5 (unload_dialog DCL_ID)
Unloads a DCL file from memory.
Handling Tiles and Attributes Top
ACTION_TILE 18-10 (action_tile KEY ACTION-EXPRESSION)
Assigns an action to be evaluated when the user selects the tile specified by KEY.
GET_ATTR (get_attr KEY ATTRIBUTE)
Retrieves the DCL value of a tile attribute.
GET_TILE 18-13 (get_tile KEY)
Retrieves the current run-time value of a dialog box tile.
MODE_TILE 18-11 (mode_tile KEY MODE)
Sets the mode of a the tile specified by KEY. Allowable values for the MODE are:
Value Meaning
0 Enable tile
1 Disable tile
2 Set focus to tile
3 Select edit box contents
4 Flip image highlighting on and off
SET_TILE 18-8 (set_tile KEY VALUE)
Sets the value of the tile specified by KEY to the string specified by VALUE.
Handling List Boxes and Pop-Up Lists Top
ADD_LIST 18-18 (add_list string)
Adds or modifies a string in the currently active list box.
END_LIST 18-19 (end_list)
Ends processing of the currently active list box.
START_LIST 18-18 (start_list KEY [OPERATION [INDEX]])
Starts processing a list in the current list box or current pop-up list.
Handling Image Tiles Top
DIMX_TILE 18-23 (dimx_tile KEY)
DIMY_TILE 18-23 (dimy_tile KEY)
Retrieves the dimensions of the image tile specified by KEY in dialog box units.
END_IMAGE 18-25 (end_image)
Ends creation of the currently active image tile.
FILL_IMAGE 18-22 (fill_image X1 Y1 WID HGT COLOR)
Draws a filled rectangle in the currently active image tile.
SLIDE_IMAGE 18-29 (slide_image X1 Y1 WID HGT SLDNAME)
Displays a previously-created AutoCAD slide in the currently active image tile.
START_IMAGE 18-22 (start_image KEY)
Starts the creation of an image in the tile specified by KEY.
VECTOR_IMAGE 18-25 (vector_image X1 Y1 X2 Y2 COLOR)
Draws a vector in the currently active image tile.