autocad 2013 Reference Guide

AutoCAD 2013
AutoLISP Reference Guide
January 2012
©
2012 Autodesk, Inc. All Rights Reserved. Except as otherwise permitted by Autodesk, Inc., this publication, or parts thereof, may not
be reproduced in any form, by any method, for any purpose.
Certain materials included in this publication are reprinted with the permission of the copyright holder.
Trademarks
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.

Contents

Chapter 1 AutoLISP Functions . . . . . . . . . . . . . . . . . . . . . . . . . 1
AutoLISP Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
+ (add) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
- (subtract) . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
* (multiply) . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
/ (divide) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
= (equal to) . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
/= (not equal to) . . . . . . . . . . . . . . . . . . . . . . . . 6
< (less than) . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
<= (less than or equal to) . . . . . . . . . . . . . . . . . . . . 8
> (greater than) . . . . . . . . . . . . . . . . . . . . . . . . . 9
>= (greater than or equal to) . . . . . . . . . . . . . . . . . . 9
~ (bitwise NOT) . . . . . . . . . . . . . . . . . . . . . . . . 10
1+ (increment) . . . . . . . . . . . . . . . . . . . . . . . . 11
1- (decrement) . . . . . . . . . . . . . . . . . . . . . . . . . 12
A Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
abs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
acad-pop-dbmod . . . . . . . . . . . . . . . . . . . . . . . 13
acad-push-dbmod . . . . . . . . . . . . . . . . . . . . . . . 13
acad_strlsort . . . . . . . . . . . . . . . . . . . . . . . . . . 14
acad_truecolorcli . . . . . . . . . . . . . . . . . . . . . . . 15
acad_truecolordlg . . . . . . . . . . . . . . . . . . . . . . . 16
acdimenableupdate . . . . . . . . . . . . . . . . . . . . . . 17
iii
acet-layerp-mode . . . . . . . . . . . . . . . . . . . . . . . 18
acet-layerp-mark . . . . . . . . . . . . . . . . . . . . . . . 19
alert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
alloc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
and . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
angtof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
angtos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
append . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
apply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
arx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
arxload . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
arxunload . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
ascii . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
assoc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
atan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
atof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
atoi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
atom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
atoms-family . . . . . . . . . . . . . . . . . . . . . . . . . 33
autoarxload . . . . . . . . . . . . . . . . . . . . . . . . . . 33
autoload . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
B Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Boole . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
boundp . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
C Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
caddr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
cadr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
car . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
cdr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
chr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
close . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
command . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
command-s . . . . . . . . . . . . . . . . . . . . . . . . . . 43
cond . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
cons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
cos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
cvunit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
D Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
defun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
defun-q . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
defun-q-list-ref . . . . . . . . . . . . . . . . . . . . . . . . 54
defun-q-list-set . . . . . . . . . . . . . . . . . . . . . . . . 55
dictadd . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
dictnext . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
dictremove . . . . . . . . . . . . . . . . . . . . . . . . . . 59
iv | Contents
dictrename . . . . . . . . . . . . . . . . . . . . . . . . . . 60
dictsearch . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
distance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
distof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
dumpallproperties . . . . . . . . . . . . . . . . . . . . . . . 64
E Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
entdel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
entget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
entlast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
entmake . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
entmakex . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
entmod . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
entnext . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
entsel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
entupd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
eq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
equal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
*error* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
eval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
exp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
expand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
expt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
F Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
findfile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
fix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
float . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
foreach . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
G Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
gc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
gcd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
getangle . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
getcfg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
getcname . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
getcorner . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
getdist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
getenv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
getfiled . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
getint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
getkword . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
getorient . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
getpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
getpropertyvalue . . . . . . . . . . . . . . . . . . . . . . . 103
getreal . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
getstring . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Contents | v
getvar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
graphscr . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
grclear . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
grdraw . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
grread . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
grtext . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
grvecs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
H Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
handent . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
I Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
initcommandversion . . . . . . . . . . . . . . . . . . . . 116
initdia . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
initget . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
ispropertyreadonly . . . . . . . . . . . . . . . . . . . . . . 123
inters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
itoa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
L Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
lambda . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
last . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
layoutlist . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
layerstate-addlayers . . . . . . . . . . . . . . . . . . . . . 128
layerstate-compare . . . . . . . . . . . . . . . . . . . . . . 129
layerstate-delete . . . . . . . . . . . . . . . . . . . . . . . 130
layerstate-export . . . . . . . . . . . . . . . . . . . . . . . 130
layerstate-getlastrestored . . . . . . . . . . . . . . . . . . . 131
layerstate-getlayers . . . . . . . . . . . . . . . . . . . . . . 131
layerstate-getnames . . . . . . . . . . . . . . . . . . . . . 132
layerstate-has . . . . . . . . . . . . . . . . . . . . . . . . . 132
layerstate-import . . . . . . . . . . . . . . . . . . . . . . . 133
layerstate-importfromdb . . . . . . . . . . . . . . . . . . . 133
layerstate-removelayers . . . . . . . . . . . . . . . . . . . 134
layerstate-rename . . . . . . . . . . . . . . . . . . . . . . 134
layerstate-restore . . . . . . . . . . . . . . . . . . . . . . . 135
layerstate-save . . . . . . . . . . . . . . . . . . . . . . . . 135
length . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
listp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
logand . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
logior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
lsh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
M Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
mapcar . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
max . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
vi | Contents
mem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
member . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
menucmd . . . . . . . . . . . . . . . . . . . . . . . . . . 147
min . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
minusp . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
N Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
namedobjdict . . . . . . . . . . . . . . . . . . . . . . . . 149
nentsel . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
nentselp . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
nth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
null . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
numberp . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
O Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
open . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
osnap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
P Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
polar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
prin1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
princ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
print . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
progn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Q Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
quit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
quote . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
R Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
read-char . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
read-line . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
redraw . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
regapp . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
rem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
repeat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
reverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
rtos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
S Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
setcfg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
setenv . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
setpropertyvalue . . . . . . . . . . . . . . . . . . . . . . . 175
setq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
setvar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
setview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
sin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Contents | vii
snvalid . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
sqrt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
ssadd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
ssdel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
ssget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
ssgetfirst . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
sslength . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
ssmemb . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
ssname . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
ssnamex . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
sssetfirst . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
startapp . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
strcase . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
strcat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
strlen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
subst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
substr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
T Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
tblnext . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
tblobjname . . . . . . . . . . . . . . . . . . . . . . . . . . 203
tblsearch . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
terpri . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
textbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
textpage . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
textscr . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
trace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
trans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
U Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
untrace . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
V Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
ver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
vl-acad-defun . . . . . . . . . . . . . . . . . . . . . . . . 214
vl-acad-undefun . . . . . . . . . . . . . . . . . . . . . . . 215
vl-bb-ref . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
vl-bb-set . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
vl-catch-all-apply . . . . . . . . . . . . . . . . . . . . . . 216
vl-catch-all-error-message . . . . . . . . . . . . . . . . . . 218
vl-catch-all-error-p . . . . . . . . . . . . . . . . . . . . . . 219
vl-cmdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
vl-consp . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
vl-directory-files . . . . . . . . . . . . . . . . . . . . . . . 222
vl-doc-ref . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
vl-doc-set . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
vl-every . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
vl-exit-with-error . . . . . . . . . . . . . . . . . . . . . . . 226
viii | Contents
vl-exit-with-value . . . . . . . . . . . . . . . . . . . . . . 227
vl-file-copy . . . . . . . . . . . . . . . . . . . . . . . . . . 227
vl-file-delete . . . . . . . . . . . . . . . . . . . . . . . . . 229
vl-file-directory-p . . . . . . . . . . . . . . . . . . . . . . 229
vl-file-rename . . . . . . . . . . . . . . . . . . . . . . . . 230
vl-file-size . . . . . . . . . . . . . . . . . . . . . . . . . . 231
vl-file-systime . . . . . . . . . . . . . . . . . . . . . . . . 231
vl-filename-base . . . . . . . . . . . . . . . . . . . . . . . 232
vl-filename-directory . . . . . . . . . . . . . . . . . . . . 233
vl-filename-extension . . . . . . . . . . . . . . . . . . . . 234
vl-filename-mktemp . . . . . . . . . . . . . . . . . . . . . 234
vl-list* . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
vl-list->string . . . . . . . . . . . . . . . . . . . . . . . . . 237
vl-list-length . . . . . . . . . . . . . . . . . . . . . . . . . 237
vl-load-all . . . . . . . . . . . . . . . . . . . . . . . . . . 238
vl-mkdir . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
vl-member-if . . . . . . . . . . . . . . . . . . . . . . . . . 239
vl-member-if-not . . . . . . . . . . . . . . . . . . . . . . . 240
vl-position . . . . . . . . . . . . . . . . . . . . . . . . . . 241
vl-prin1-to-string . . . . . . . . . . . . . . . . . . . . . . . 242
vl-princ-to-string . . . . . . . . . . . . . . . . . . . . . . . 243
vl-propagate . . . . . . . . . . . . . . . . . . . . . . . . . 243
vl-registry-delete . . . . . . . . . . . . . . . . . . . . . . . 244
vl-registry-descendents . . . . . . . . . . . . . . . . . . . 245
vl-registry-read . . . . . . . . . . . . . . . . . . . . . . . . 246
vl-registry-write . . . . . . . . . . . . . . . . . . . . . . . 246
vl-remove . . . . . . . . . . . . . . . . . . . . . . . . . . 247
vl-remove-if . . . . . . . . . . . . . . . . . . . . . . . . . 248
vl-remove-if-not . . . . . . . . . . . . . . . . . . . . . . . 249
vl-some . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
vl-sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
vl-sort-i . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
vl-string->list . . . . . . . . . . . . . . . . . . . . . . . . . 253
vl-string-elt . . . . . . . . . . . . . . . . . . . . . . . . . . 254
vl-string-left-trim . . . . . . . . . . . . . . . . . . . . . . 254
vl-string-mismatch . . . . . . . . . . . . . . . . . . . . . . 255
vl-string-position . . . . . . . . . . . . . . . . . . . . . . 256
vl-string-right-trim . . . . . . . . . . . . . . . . . . . . . . 257
vl-string-search . . . . . . . . . . . . . . . . . . . . . . . . 258
vl-string-subst . . . . . . . . . . . . . . . . . . . . . . . . 258
vl-string-translate . . . . . . . . . . . . . . . . . . . . . . 260
vl-string-trim . . . . . . . . . . . . . . . . . . . . . . . . . 260
vl-symbol-name . . . . . . . . . . . . . . . . . . . . . . . 261
vl-symbol-value . . . . . . . . . . . . . . . . . . . . . . . 262
vl-symbolp . . . . . . . . . . . . . . . . . . . . . . . . . . 262
vports . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
Contents | ix
W Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
wcmatch . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
write-char . . . . . . . . . . . . . . . . . . . . . . . . . . 268
write-line . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
X Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
xdroom . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
xdsize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
Z Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
zerop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Chapter 2 Externally Defined Commands . . . . . . . . . . . . . . . . . 273
Externally Defined Commands . . . . . . . . . . . . . . . . . . . . . 273
align . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
cal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
mirror3d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
rotate3d . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
solprof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
x | Contents

AutoLISP Functions

AutoLISP Functions

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 AutoLISP Developer'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.
(acad-push-dbmod) (setq new_line '((0 . "LINE") (100 . "AcDbEntity") (8 . "0")
(100 . "AcDbLine") (10 1.0 2.0 0.0) (11 2.0
1.0 0.0) (210 0.0 0.0 1.0)))
(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.
Examples
Sort a list of abbreviated month names:
Command: (setq mos '("Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"))
("Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec")
Command: (acad_strlsort mos) ("Apr" "Aug" "Dec" "Feb" "Jan" "Jul" "Jun" "Mar" "May" "Nov" "Oct" "Sep")
acad_truecolorcli
Prompts for colors at the command line
(acad_truecolorcli
color [allowbylayer] [alternatePrompt]
)
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 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:
Command: (acad_truecolordlg '(62 . 215)) ((62 . 215))
Open the color selection dialog to the True Color tab with a green default selection and with the By Layer and By Block buttons disabled:
Command: (acad_truecolordlg '(420 . 2686760) nil) ((62 . 80) (420 . 2686760))
Open the color selection dialog to the Color Books tab and accept the mustard default selection:
Command: (acad_truecolordlg '(430 . "RAL CLASSIC$RAL 1003")) ((62 . 40) (420 . 16235019) (430 . "RAL CLASSIC$RAL 1003"))
acdimenableupdate
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