All other brand names, product names or trademarks belong to their respective holders.
Disclaimer
THIS PUBLICATION AND THE INFORMATION CONTAINED HEREIN IS MADE AVAILABLE BY AUTODESK, INC. "AS IS." AUTODESK, INC. DISCLAIMS
ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR
FITNESS FOR A PARTICULAR PURPOSE REGARDING THESE MATERIALS.
The following is a catalog of the AutoLISP® functions available in AutoCAD®.
The functions are listed alphabetically.
In this chapter, 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.
Note that any functions, variables, or features not described here or in other
parts of the documentation are not officially supported and are subject to change
in future releases.
For information on syntax, see AutoLISP Function Syntax in the AutoLISPDeveloper's Guide.
1
Note that the value returned by some functions is categorized as unspecified.
This indicates you cannot rely on using the value returned from this function.
Operators
+ (add)
Returns the sum of all numbers.
(+
[number number]
...)
1
Arguments
number A number.
Return Values
The result of the addition. If you supply only one number argument, this
function returns the result of adding it to zero. If you supply no arguments,
the function returns 0.
Examples
(+ 1 2)
returns
3
(+ 1 2 3 4.5)
returns
10.5
(+ 1 2 3 4.0)
returns
10.0
- (subtract)
Subtracts the second and following numbers from the first and returns the
difference
(-
[number number]
...)
Arguments
number A number.
Return Values
The result of the subtraction. If you supply more than two number arguments,
this function returns the result of subtracting the sum of the second through
the last numbers from the first number. If you supply only one number
argument, this function subtracts the number from zero, and returns a negative
number. Supplying no arguments returns 0.
Examples
2 | Chapter 1 AutoLISP Functions
(- 50 40)
returns
10
(- 50 40.0)
returns
10.0
(- 50 40.0 2.5)
returns
7.5
(- 8)
returns
-8
* (multiply)
Returns the product of all numbers
(*
[number number]
...)
Arguments
number A number.
Return Values
The result of the multiplication. If you supply only one number argument,
this function returns the result of multiplying it by one; it returns the number.
Supplying no arguments returns 0.
Examples
(* 2 3)
returns
6
(* 2 3.0)
returns
6.0
(* 2 3 4.0)
AutoLISP Functions | 3
returns
24.0
(* 3 -4.5)
returns
-13.5
(* 3)
returns
3
/ (divide)
Divides the first number by the product of the remaining numbers and returns
the quotient
(/
[number number]
...)
Arguments
number A number.
Return Values
The result of the division. If you supply more than two number arguments,
this function divides the first number by the product of the second through
the last numbers, and returns the final quotient. If you supply one number
argument, this function returns the result of dividing it by one; it returns the
number. Supplying no arguments returns 0.
Examples
(/ 100 2)
returns
50
(/ 100 2.0)
returns
50.0
(/ 100 20.0 2)
returns
4 | Chapter 1 AutoLISP Functions
2.5
(/ 100 20 2)
returns
2
(/ 4)
returns
4
= (equal to)
Compares arguments for numerical equality
(=
numstr [numstr]
...)
Arguments
numstr A number or a string.
Return Values
T, if all arguments are numerically equal; otherwise nil . If only one argument
is supplied, = returns T.
Examples
(= 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
AutoLISP Functions | 5
T
(= "me" "you")
returns
nil
See also:
The eq (page 80) and equal (page 81) functions.
/= (not equal to)
Compares arguments for numerical inequality
(/=
numstr [numstr]
...)
Arguments
numstr A number or a string.
Return Values
T, if no two successive arguments are the same in value; otherwise nil. If only
one argument is supplied, /= returns T.
Note that the behavior of /= does not quite conform to other LISP dialects.
The standard behavior is to return T if no two arguments in the list have the
same value. In AutoLISP, /= returns T if no successive arguments have the same
value; see the examples that follow.
Examples
(/= 10 20)
returns
T
(/= "you" "you")
returns
nil
(/= 5.43 5.44)
returns
6 | Chapter 1 AutoLISP Functions
T
(/= 10 20 10 20 20)
returns
nil
(/= 10 20 10 20)
returns
T
NOTE In the last example, although there are two arguments in the list with the
same value, they do not follow one another; thus /= evaluates to T.
< (less than)
Returns T if each argument is numerically less than the argument to its right;
otherwise nil
(<
numstr [numstr]
...)
Arguments
numstr A number or a string.
Return Values
T, if each argument is numerically less than the argument to its right; otherwise
returns nil . If only one argument is supplied, < returns T.
Examples
(< 10 20)
returns
T
(< "b" "c")
returns
T
(< 357 33.2)
returns
nil
(< 2 3 88)
AutoLISP Functions | 7
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; otherwise returns nil
(<=
numstr [numstr]
...)
Arguments
numstr A number or a string.
Return Values
T, if each argument is numerically less than or equal to the argument to its
right; otherwise returns nil. If only one argument is supplied, <= returns T.
Examples
(<= 10 20)
returns
T
(<= "b" "b")
returns
T
(<= 357 33.2)
returns
nil
(<= 2 9 9)
returns
T
(<= 2 9 4 5)
returns
nil
8 | Chapter 1 AutoLISP Functions
> (greater than)
Returns T if each argument is numerically greater than the argument to its
right; otherwise returns nil
(>
numstr [numstr]
...)
Arguments
numstr A number or a string.
Return Values
T, if each argument is numerically greater than the argument to its right;
otherwise nil. If only one argument is supplied, > returns T.
Examples
(> 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; otherwise returns nil
AutoLISP Functions | 9
(>=
numstr [numstr]
...)
Arguments
numstr A number or a string.
Return Values
T, if each argument is numerically greater than or equal to the argument to
its right; otherwise nil. If only one argument is supplied, >= returns T.
Examples
(>= 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
)
Arguments
10 | Chapter 1 AutoLISP Functions
int An integer.
Return Values
The bitwise NOT (1's complement) of the argument.
Examples
(~ 3)
returns
-4
(~ 100)
returns
-101
(~ -4)
returns
3
1+ (increment)
Increments a number by 1
(1+
number
)
Arguments
number Any number.
Return Values
The argument, increased by 1.
Examples
(1+ 5)
returns
6
(1+ -17.5)
returns
-16.5
AutoLISP Functions | 11
1- (decrement)
Decrements a number by 1
(1-
number
)
Arguments
number Any number.
Return Values
The argument, reduced by 1.
Examples
(1- 5)
returns
4
(1- -17.5)
returns
-18.5
A Functions
abs
Returns the absolute value of a number
(abs
number
)
Arguments
number Any number.
Return Values
12 | Chapter 1 AutoLISP Functions
The absolute value of the argument.
Examples
(abs 100)
returns
100
(abs -100)
returns
100
(abs -99.25)
returns
99.25
acad-pop-dbmod
Restores the value of the DBMOD system variable to the value that was most
recently stored with acad-push-dbmod
(acad-pop-dbmod)
This function is used with acad-push-dbmod to control the DBMOD system
variable. The DBMOD system variable tracks changes to a drawing and triggers
save-drawing queries.
This function is implemented in acapp.arx, which is loaded by default. This
function pops the current value of the DBMOD system variable off an internal
stack.
Return Values
Returns T if successful; otherwise, if the stack is empty, returns nil.
acad-push-dbmod
Stores the current value of the DBMOD system variable
(acad-push-dbmod)
This function is used with acad-pop-dbmod to control the DBMOD system
variable. You can use this function to change a drawing without changing
AutoLISP Functions | 13
the DBMOD system variable. The DBMOD system variable tracks changes to a
drawing and triggers save-drawing queries.
This function is implemented in acapp.arx, which is loaded by default. This
function pushes the current value of the DBMOD system variable onto an internal
stack. To use acad-push-dbmod and acad-pop-dbmod, precede operations
with acad-push-dbmod and then use acad-pop-dbmod to restore the original
value of the DBMOD system variable.
Return Values
Always returns T.
Examples
The following example shows how to store the modification status of a
drawing, change the status, and then restore the original status.
(entmake new_line); Set DBMOD to flag 1
(command "_color" "2"); Set DBMOD to flag 4
(command "_-vports" "_SI"); Set DBMOD to flag 8
(command "_vpoint" "0,0,1"); Set DBMOD to flag 16
(acad-pop-dbmod); Set DBMOD to original value
acad_strlsort
Sorts a list of strings in alphabetical order
(acad_strlsort
list
)
Arguments
list The list of strings to be sorted.
Return Values
14 | Chapter 1 AutoLISP Functions
The list in alphabetical order. If the list is invalid or if there is not enough
memory to do the sort, acad_strlsort returns nil.
color A dotted pair that describes the default color. The first element of the
dotted pair must be one of the color-related DXF group codes (62, 420, or
430); for example, (62 . ColorIndex), (420 . TrueColor), or (430 .
"colorbook$colorname").
allowbylayer Omitting the allowbylayer argument or setting it to a non-nil
value enables entering bylayer or byblock to set the color. If set to nil, an
error results if bylayer or byblock is entered.
alternateprompt An optional prompt string. If this string is omitted, the default
value is “New color”.
Return Values
When the operation is successful, the function returns a list of one or more
dotted pairs (depending on the tab on which the color is selected) describing
the color selected. The last dotted pair in the list indicates the color selected.
The function returns nil if the user cancels the function.
Color book color If the last item in the returned list is a 430 pair, then the
specified color originates from a color book. This returned list will also contain
AutoLISP Functions | 15
a 420 pair that describes the corresponding true color and a 62 pair that
describes the closest matching color index value.
True color If the returned list contains a 420 pair as the last item, then a true
color was specified (as “Red,Green,Blue”). The list will also contain a 62 pair
that indicates the closest matching color index. No 430 pair will be present.
Color index If the last item in the list is a 62 pair, then a colorindex was
chosen. No other dotted pairs will be present in the returned list.
Examples
Prompt for a color selection at the command line with a purple color index
default selection and alternative text for the command prompt:
Command: (acad_truecolorcli '(62 . 215) 1 "Pick a color")
New Color [Truecolor/COlorbook] <215>:
((62 . 215))
Prompt for a color selection at the command line with a yellow color index
default selection, then set the color by layer:
Command: (acad_truecolorcli '(62 . 2))
New Color [Truecolor/COlorbook] <2 (yellow)>: bylayer
((62 . 256))
acad_truecolordlg
Displays the AutoCAD color selection dialog box with tabs for index color,
true color, and color books
(acad_truecolordlg
color [allowbylayer] [currentlayercolor]
)
Arguments
color A dotted pair that describes the default color. The first element of the
dotted pair must be one of the color-related DXF group codes (62, 420, or
430); for example, (62 . ColorIndex), (420 . TrueColor), or (430 .
"colorbook$colorname").
allowbylayer If set to nil, disables the ByLayer and ByBlock buttons. Omitting
the allowbylayer argument or setting it to a non-nil value enables the ByLayer
and ByBlock buttons.
16 | Chapter 1 AutoLISP Functions
currentlayercolor Optional dotted pair in the same form as color that sets the
value of the bylayer/byblock color in the dialog.
Return Values
When the operation is successful, the function returns a list of one or more
dotted pairs (depending on the tab on which the color is selected) describing
the color selected. The last dotted pair in the list indicates the color selected.
The function returns nil if the user cancels the dialog box.
Color book color If the last item in the returned list is a 430 pair, then the
specified color originates from a color book. This returned list will also contain
a 420 pair that describes the corresponding true color and a 62 pair that
describes the closest matching color index value.
True color If the returned list contains a 420 pair as the last item, then a true
color was specified (as “Red,Green,Blue”). The list will also contain a 62 pair
that indicates the closest matching color index. No 430 pair will be present.
Color index If the last item in the list is a 62 pair, then a color index was
chosen. No other dotted pairs will be present in the returned list.
Examples
Open the color selection dialog to the Color Index tab and accept the purple
default selection:
Controls the automatic updating of associative dimensions
(acdimenableupdate nil | T)
AutoLISP Functions | 17
The acdimenableupdate function is intended for developers who are editing
geometry and don't want the dimension to be updated until after the edits
are complete.
Arguments
nil Associative dimensions will not update (even if the geometry is modified)
until the DIMREGEN command is entered.
T Enable automatic updating of associative dimensions when the geometry
is modified.
Return Values
nil
Examples
Disable the automatic update of associative dimensions in the drawing:
Command: (acdimenableupdate nil)
Enable the automatic update of associative dimensions in the drawing:
Command: (acdimenableupdate T)
acet-layerp-mode
Queries and sets the LAYERPMODE setting
(acet-layerp-mode [
status
])
Arguments
status Specifying T turns LAYERPMODE on, enabling layer-change tracking.
Nil turns LAYERPMODE off.
If this argument is not present, acet-layerp-mode returns the current status
of LAYERPMODE.
Return Values
T if current status of LAYERPMODE is on; nil if LAYERPMODE is off.
Examples
Check the current status of LAYERPMODE:
Command: (acet-layerp-mode)
18 | Chapter 1 AutoLISP Functions
T
Turn LAYERPMODE off:
Command: (acet-layerp-mode nil)
nil
Check the current status of LAYERPMODE:
Command: (acet-layerp-mode)
nil
See also:
The LAYERP and LAYERPMODE commands in the Command Reference.
acet-layerp-mark
Places beginning and ending marks for Layer Previous recording
(acet-layerp-mark [
status
])
The acet-layerp-mark function allows you to group multiple layer commands
into a single transaction so that they can be undone by issuing LAYERP a
single time. LAYERPMODE must be on in order to set marks.
Arguments
status Specifying T sets a begin mark. Specifying nil sets an end mark, clearing
the begin mark.
If status is omitted, acet-layerp-mark returns the current mark status for layer
settings.
Return Values
T if a begin mark is in effect; otherwise nil.
Examples
The following code changes layer 0 to blue, and then makes several additional
layer changes between a set of begin and end marks. If you issue LAYERP after
running this code, layer 0 reverts to blue.
(defun TestLayerP ()
AutoLISP Functions | 19
;; Turn LAYERPMODE on, if it isn't already
(if (not (acet-layerp-mode))
(acet-layerp-mode T)
)
;; Set layer 0 to the color blue
(command "_.layer" "_color" "blue" "0" "")
;; Set a begin mark
(acet-layerp-mark T)
;; Issue a series of layer commands, and then set an end
mark
(command "_.layer" "_color" "green" "0" "")
(command "_.layer" "_thaw" "*" "")
(command "_.layer" "_unlock" "*" "")
(command "_.layer" "_ltype" "hidden" "0" "")
(command "_.layer" "_color" "red" "0" "")
;; Set an end mark
(acet-layerp-mark nil)
)
See also:
The LAYERP command in the Command Reference.
alert
Displays a dialog box containing an error or warning message
(alert
string
)
Arguments
string The string to appear in the alert box.
Return Values
nil
Examples
Display a message in an alert box:
(alert "That function is not available.")
20 | Chapter 1 AutoLISP Functions
Loading...
+ 268 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.