Find and compare CAD & BIM software. Access objective reviews, comparisons, and 400+ free engineering utilities.
CGCADGuide.tools
AutoCAD Scripting

AutoLISP Function
Quick Reference

50+ AutoLISP functions for AutoCAD automation — math, geometry, entity access, selection sets, list operations, and command execution. Search by function name or category.

Exploring AutoLISP Workflows or Planning a Transition?
Check out popular comparison reports and companion tools for this software
(+ a b)Addition

Returns sum of all arguments. (+ 2 3 4) → 9. Accepts integers and reals. Result type: integer if all args are integers, real if any arg is real.

(- a b)Subtraction

Returns difference. (- 10 3 2) → 5. With one argument, negates: (- 5) → -5. Same type rules as +.

(* a b)Multiplication

Returns product. (* 2 3 4) → 24. Same type rules as + and -.

(/ a b)Division

Returns quotient. (/ 10 3) → 3 (integer division). (/ 10.0 3) → 3.33333 (real division). Use float arg for real result.

(1+ n)Increment

Returns n + 1. (1+ 5) → 6. Works with integers and reals. Not the same as (+ n 1) — 1+ is a dedicated function.

(1- n)Decrement

Returns n - 1. (1- 5) → 4. Works with integers and reals.

(abs n)Absolute Value

Returns absolute value. (abs -5) → 5. (abs -5.5) → 5.5.

(sin ang)Sine

Returns sine of angle in radians. (sin 0.0) → 0.0. (sin (/ pi 2)) → 1.0. Always returns real.

(cos ang)Cosine

Returns cosine of angle in radians. (cos 0.0) → 1.0. (cos pi) → -1.0. Always returns real.

(atan a b)Arctangent

With one arg: returns arctangent in radians. (atan 1.0) → 0.785398 (π/4). With two args: returns arctangent of a/b, handling quadrant correctly (like atan2 in C).

(sqrt n)Square Root

Returns square root as real. (sqrt 16) → 4.0. Always returns real regardless of input type.

(expt base exp)Exponent

Returns base raised to power exp. (expt 2 3) → 8. (expt 2.0 0.5) → 1.41421.

(gcd a b)GCD

Returns greatest common divisor of two positive integers. (gcd 12 18) → 6. Arguments must be integers.

(rem a b)Remainder

Returns remainder of integer division. (rem 10 3) → 1. Sign follows first argument.

(and a b)Logical AND

Returns T if all arguments are non-nil, nil otherwise. Short-circuits on first nil. (and T T nil) → nil.

(or a b)Logical OR

Returns T if any argument is non-nil, nil otherwise. Short-circuits on first non-nil. (or nil T nil) → T.

(not a)Logical NOT

Returns T if argument is nil, nil otherwise. (not nil) → T. (not 5) → nil. Different from null — not works on any expression.

(= a b)Equal

Returns T if all arguments are numerically equal. (= 5 5) → T. (= 5 5.0) → T. (= "abc" "abc") → T.

(/= a b)Not Equal

Returns T if any pair of arguments is not equal. (/= 5 6) → T.

(< a b)Less Than

Returns T if each argument is less than the next. (< 1 2 3) → T. Works with numbers and strings.

(> a b)Greater Than

Returns T if each argument is greater than the next. (> 3 2 1) → T.

(<= a b)Less or Equal

Returns T if each argument is less than or equal to the next. (<= 1 1 2) → T.

(>= a b)Greater or Equal

Returns T if each argument is greater than or equal to the next. (>= 3 3 2) → T.

(distance p1 p2)Distance

Returns 3D distance between two points. (distance '(0 0 0) '(3 4 0)) → 5.0. Points must be lists of 2 or 3 reals.

(angle p1 p2)Angle

Returns angle in radians from p1 to p2 (XY plane only). (angle '(0 0) '(1 0)) → 0.0. (angle '(0 0) '(0 1)) → 1.5708 (π/2).

(polar pt ang dist)Polar Point

Returns a point at given angle (radians) and distance from pt. (polar '(0 0) 0.0 5.0) → (5.0 0.0). Extremely useful for calculating points in AutoLISP.

(inters l1p1 l1p2 l2p1 l2p2)Intersection

Returns intersection point of two lines defined by point pairs. Optional 5th arg nil extends lines. (inters '(0 0) '(10 10) '(0 10) '(10 0)) → (5.0 5.0).

(osnap pt mode)Object Snap

Returns snap point using OSNAP mode string. (osnap pt "midp") returns midpoint of nearest entity. Modes: "endp","midp","cen","int","nea","nod","qua","tan","per","ins","app". Returns nil if no snap found.

(angle p1 p2)Angle in Radians

Returns angle from p1 to p2 in radians (XY plane). To convert to degrees: (* (/ (angle p1 p2) pi) 180).

(cvunit val from to)Unit Conversion

Converts value between units. (cvunit 1 "inch" "mm") → 25.4. Uses acad.unt file. Supports distance, area, volume, angle, mass, and temperature units.

(trans pt from to)Coordinate Transform

Transforms point between coordinate systems. from/to can be: 0=WCS, 1=UCS, 2=DCS, or an entity name. (trans pt 1 0) converts from UCS to WCS.

(entget ename)Get Entity Data

Returns association list (DXF group codes) for entity. (entget (entlast)) returns data for last entity. Key codes: 0=type, 8=layer, 10=start point, 11=end point, 40=radius.

(entlast)Last Entity

Returns entity name of the last non-deleted entity in the drawing. Common pattern: (setq ent (entlast)) before creating entities to track them.

(entnext ename)Next Entity

Returns entity name of the next entity in the database. (entnext nil) returns first entity. Used to iterate through all entities. Returns nil at end.

(entmake datalist)Make Entity

Creates a new entity from DXF group code list. (entmake (list '(0 ."CIRCLE") '(8 ."0") '(10 0.0 0.0 0.0) '(40 . 5.0))). Faster than command for bulk creation.

(entmod datalist)Modify Entity

Modifies an entity using updated DXF group code list. Pattern: (setq ed (entget en)) (setq ed (subst (cons 8 "NewLayer") (assoc 8 ed) ed)) (entmod ed). Changes are immediate.

(entdel ename)Delete Entity

Deletes or undeletes an entity. (entdel en) deletes. Calling again with same ename undeletes. Cannot delete entities in blocks.

(entupd ename)Update Entity

Regenerates entity on screen after modification. Especially needed for polylines and complex entities after entmod. (entupd en) updates display.

(ssget mode pt1 pt2)Selection Set

Creates selection set. Modes: "C"=crossing, "W"=window, "L"=last, "P"=previous, "X"=all. (ssget '(0 0) '(10 10)) prompts user. (ssget "X" '((0 ."CIRCLE"))) selects all circles.

(ssname ss index)Get Entity from SS

Returns entity name at index in selection set. (ssname ss 0) returns first entity. Index is 0-based. Use with ssadd/ssdel to manipulate sets.

(sslength ss)Selection Set Length

Returns number of entities in selection set. (sslength ss) → integer count. Use to iterate: (while (< i (sslength ss)) ...).

(ssadd ename ss)Add to Selection Set

Adds entity to selection set. (ssadd en ss) adds en to ss. If ss is nil, creates new selection set. Returns the selection set.

(ssdel ename ss)Remove from Selection Set

Removes entity from selection set. (ssdel en ss) removes en from ss. Returns ss if successful, nil if entity not in set.

(ssmemb ename ss)Test Membership

Returns ename if entity is in selection set, nil otherwise. (ssmemb en ss) checks if en is in ss.

(nentsel)Nested Entity Select

Prompts user to select entity, returns (ename pt). For nested entities (in blocks), returns the sub-entity, not the block reference. Useful for editing attributes and block contents.

(entsel)Entity Select

Prompts user to select single entity. Returns (ename pickpoint). (entsel "\nSelect object: ") prompts with custom message.

(list a b c)Create List

Creates a list from arguments. (list 1 2 3) → (1 2 3). (list 0.0 0.0 0.0) creates a 3D point. Essential for coordinate data.

(car lst)First Element

Returns first element of list. (car '(1 2 3)) → 1. (car '(5.0 3.0 0.0)) → 5.0 (X coordinate). nil for empty list.

(cdr lst)Rest of List

Returns list without first element. (cdr '(1 2 3)) → (2 3). nil for empty or single-element list.

(cadr lst)Second Element

Returns second element. (cadr '(1 2 3)) → 2. (cadr pt) → Y coordinate. Equivalent to (car (cdr lst)).

(caddr lst)Third Element

Returns third element. (caddr '(1 2 3)) → 3. (caddr pt) → Z coordinate. Equivalent to (car (cdr (cdr lst))).

(nth n lst)Nth Element

Returns element at index n (0-based). (nth 2 '(a b c d)) → c. Returns nil if index out of range.

(length lst)List Length

Returns number of elements in list. (length '(1 2 3 4)) → 4. Returns 0 for nil.

(append l1 l2)Append Lists

Concatenates lists. (append '(1 2) '(3 4)) → (1 2 3 4). All arguments must be lists. (append nil '(1)) → (1).

(reverse lst)Reverse List

Returns list in reverse order. (reverse '(1 2 3)) → (3 2 1). Useful for iterating backwards or building lists efficiently.

(assoc key alist)Association Lookup

Searches association list for key. (assoc 8 (entget en)) returns (8 ."LayerName"). Essential for DXF group code access. Returns nil if not found.

(subst new old lst)Substitute

Replaces all occurrences of old with new in list. (subst (cons 8 "NewLayer") (assoc 8 ed) ed) changes layer in entity data. Returns modified list.

(member expr lst)Member Search

Returns tail of list starting from first occurrence of expr. (member 'b '(a b c d)) → (b c d). Returns nil if not found.

(foreach item lst body)For Each

Iterates over list, binding each element to item. (foreach pt ptlist (command "POINT" pt)). Executes body for each element.

(mapcar func l1 l2)Map Function

Applies function to corresponding elements. (mapcar '+ '(1 2 3) '(4 5 6)) → (5 7 9). Very powerful for coordinate transformations.

(command "LINE" pt1 pt2 "")Execute Command

Executes AutoCAD command with arguments."" = Enter. (command "CIRCLE" center radius). Use "" for command termination. Non-nil args are passed as typed. Use pauses for user input.

(getpoint prompt)Get Point

Prompts user to pick a point. Returns 3D point or nil. (getpoint "\nPick a point: "). Optional base point arg: (getpoint basept prompt) rubber-bands from basept.

(getcorner basept prompt)Get Corner

Prompts user to pick second corner, rubber-banding from basept. Returns 3D point. Used for window selection rectangles.

(getdist prompt)Get Distance

Prompts user for distance. Accepts numeric input or two picks. Returns real. (getdist pt "\nEnter radius: ") rubber-bands from pt.

(getangle prompt)Get Angle

Prompts user for angle. Returns radians regardless of current ANGDIR/ANGBASE settings. (getangle pt "\nEnter angle: ") rubber-bands from pt.

(getstring prompt)Get String

Prompts user for string input. Returns string. (getstring T "\nEnter description: ") — T allows spaces. Without T, input terminates at space.

(getint prompt)Get Integer

Prompts user for integer input. Returns integer or nil. (getint "\nEnter number of copies: ").

(getreal prompt)Get Real

Prompts user for real number. Returns real or nil. (getreal "\nEnter scale factor: ").

(getkword prompt)Get Keyword

Prompts user for keyword from initget list. Must call (initget) first. (initget 1 "Yes No") (getkword "\nContinue? [Yes/No]: ") → "Yes" or "No".

(initget bits kwords)Initialize Input

Sets input options for next getxxx call. Bits: 1=no null, 2=no zero, 4=no negative, 8=no limits check, 32=use dashed lines, 64=disable Z. Keywords string: "Yes No Cancel".

(prompt msg)Prompt Message

Displays message on command line. (prompt "\nProcessing..."). Returns nil. Use \n for new line. For dialog messages, use alert or msgbox.

(princ expr)Print Clean

Prints expression without quotes or newlines. (princ "Hello") prints Hello. Returns its argument. Common in error handlers: (princ) suppresses return value display.

(print expr)Print with Newline

Prints expression on new line with quotes for strings. (print "Hello") prints "Hello" on new line. Returns expression. Used for debugging.

(alert msg)Alert Dialog

Displays modal dialog with message and OK button. (alert "File not found!"). Message limited to ~132 characters. Returns nil.

(getvar name)Get System Variable

Returns value of AutoCAD system variable. (getvar "DIMSCALE") → current dimscale. (getvar "CLAYER") → current layer name. Returns integer, real, string, or list.

(setvar name value)Set System Variable

Sets AutoCAD system variable. (setvar "OSMODE" 0) disables all osnaps. (setvar "CMDECHO" 0) suppresses command prompts. Always restore original values after use.

(set sym expr)Set Symbol

Sets value of quoted symbol. (set 'myvar 5) → 5. Rare — use setq instead. Useful when symbol name is computed at runtime.

(setq sym1 val1 sym2 val2)Set Quote

Most common assignment. (setq x 10 y 20 z 30) assigns multiple variables. Each pair: symbol (not quoted) and value. Returns last value.

(defun name args body)Define Function

Defines a function. (defun c:MYCMD () (alert "Hello")) creates command MYCMD. Args: (/ local vars) for locals, () for none. c: prefix makes it an AutoCAD command.

(lambda args body)Lambda Function

Anonymous function. (mapcar (lambda (x) (* x 2)) '(1 2 3)) → (2 4 6). Used with mapcar and apply. No name — defined inline.

(apply func list)Apply Function

Calls function with list as arguments. (apply '+ '(1 2 3 4)) → 10. (apply 'strcat '("a" "b" "c")) → "abc". Useful when argument count is dynamic.

(strcat s1 s2)String Concatenate

Concatenates strings. (strcat "Hello" " " "World") → "Hello World". All arguments must be strings. nil causes error.

(itoa n)Integer to String

Converts integer to string. (itoa 42) → "42". For reals, use (rtos n 2 2) → "42.00" (mode 2=decimal, precision 2).

(atoi s)String to Integer

Converts string to integer. (atoi "42") → 42. (atoi "42.9") → 42 (truncates). Returns 0 for non-numeric strings.

(atof s)String to Real

Converts string to real. (atof "42.5") → 42.5. Returns 0.0 for non-numeric strings.

(rtos n mode prec)Real to String

Converts real to formatted string. Mode: 1=scientific, 2=decimal, 3=engineering, 4=architectural, 5=fractional. (rtos 3.14159 2 2) → "3.14".

(strlen s)String Length

Returns length of string. (strlen "Hello") → 5. Returns 0 for empty string.

(substr s start len)Substring

Returns substring starting at position (1-based). (substr "Hello World" 7 5) → "World". Optional length arg; without it, returns to end.

(while test body)While Loop

Executes body while test is non-nil. (while (< i 10) (setq i (1+ i))). Returns value of last expression in body. Common for iteration.

(if test then else)If Conditional

Evaluates then if test is non-nil, else otherwise. (if (> x 0) "positive" "non-positive"). else is optional. Single expression per branch — use (progn) for multiple.

(cond (test1 result1) (test2 result2) (T default))Cond Conditional

Multi-branch conditional. Evaluates tests in order, returns first matching result. T as last test = default. (cond ((= x 1) "one") ((= x 2) "two") (T "other")).

(progn expr1 expr2)Progn Block

Groups multiple expressions into one. Used with if/while. (if test (progn (setq x 1) (setq y 2))). Returns value of last expression.

(repeat n body)Repeat Loop

Executes body n times. (repeat 5 (command "POINT" (getpoint))). Returns value of last evaluation. n is evaluated once at start.

(vl-load-com)Load VLISP COM

Loads Visual LISP COM extension. Required before using vlax, vla-, and vl- functions. Call once at start of script. Enables ActiveX automation and extended entity access.

AutoLISP Advanced Efficiency Guide

AutoLISP Efficiency Optimization & Best Practices

Defun with c: prefix creates AutoCAD commands

A function named with the c: prefix becomes an AutoCAD command. (defun c:HELLO () (alert "Hi!")) lets you type HELLO at the command line. Local variables go after the slash: (defun c:MYCMD (/ pt rad) ...). Always use error handler (defun *error* msg ...) to restore system variables on exit.

Use entmake instead of command for bulk creation

When creating many entities, (entmake ...) is 10-100× faster than (command ...). entmake bypasses the command processor and writes directly to the drawing database. Pattern: build a DXF group code list with required codes (0=type, 8=layer, 10=point, etc.) and call (entmake list). No screen redraw needed during creation.

Engineering Methodology & Design Standards: AutoLISP Function Quick Reference

Discipline: CAD Interoperability, Additive Manufacturing & BIM Standards

Verified Analytical Formulation

Governing Mathematical Formulation

In professional CAD Interoperability, Additive Manufacturing & BIM Standards workflows, accurate sizing and performance verification require consistent unit normalization and adherence to closed-form analytical mechanics. This AutoLISP Function Quick Reference utility implements the standardized engineering formulation:

Standardized parametric evaluation for AutoLISP Function Quick Reference

Complete AutoLISP function reference: math, geometry, entity access, selection sets, list manipulation, and command execution for AutoCAD scripting. Every input change triggers an instant client-side recalculation across all coupled dependent variables, enabling rapid sensitivity analysis during preliminary and detailed CAD design phases.

Applicable Codes, Standards & CAD Integration

Primary Reference Standards & Codes
ISO 10303-21 (STEP AP214/AP242), ISO 16739-1 (IFC4 OpenBIM), ISO/ASTM 52900 (Additive Manufacturing), AIA CAD Layer Guidelines / ISO 19650
CAD / CAE / BIM Implementation Guidance

Validate unit system headers ($INSUNITS in DWG/DXF, FILE_SCHEMA in STEP/IFC) and enforce watertight manifold topology before dispatching files to downstream CAM, 3D printing, or BIM coordination.

Engineering Verification Note: Analytical models assume homogeneous material behavior, steady-state boundary loading, and consistent dimensional units. Always apply appropriate service factors, corrosion allowances, or load and resistance factor design (LRFD / ASD) safety margins required by your governing code.

Frequently Asked Engineering Questions

Technical reference & verification guidelines for AutoLISP Function Quick Reference

What governing equation and methodology does the AutoLISP Function Quick Reference use?

The AutoLISP Function Quick Reference evaluates complete autolisp function reference: math, geometry, entity access, selection sets, list manipulation, and command execution for autocad scripting within the CAD Interoperability, Additive Manufacturing & BIM Standards domain using the governing formulation: Standardized parametric evaluation for AutoLISP Function Quick Reference. All intermediate quantities are computed in double-precision floating-point arithmetic to prevent cumulative rounding drift before final design verification.

Which international engineering standards apply to AutoLISP Function Quick Reference calculations?

Calculations and boundary assumptions in this utility align with recognized industry references including ISO 10303-21 (STEP AP214/AP242), ISO 16739-1 (IFC4 OpenBIM), ISO/ASTM 52900 (Additive Manufacturing), AIA CAD Layer Guidelines / ISO 19650. When preparing formal calculation packages or P.E. stamp submittals, always verify local jurisdictional code amendments and project-specific safety factors.

How should I integrate results from the AutoLISP Function Quick Reference into my CAD or BIM workflow?

Validate unit system headers ($INSUNITS in DWG/DXF, FILE_SCHEMA in STEP/IFC) and enforce watertight manifold topology before dispatching files to downstream CAM, 3D printing, or BIM coordination. Using the baseline benchmark (standard nominal boundary parameters for AutoLISP Function Quick Reference), the solver yields verified design compliance metrics for AutoLISP Function Quick Reference, which can be directly cross-referenced against your parametric 3D assembly constraints, 2D fabrication drawings, or bill of materials (BOM).