Learn AUTOLISP with Real Code Examples
Updated Nov 27, 2025
Code Sample Descriptions
1
Simple AutoLISP Routine to Draw a Line
(defun c:DrawLine ()
(prompt "\nSelect first point: ")
(setq p1 (getpoint))
(prompt "\nSelect second point: ")
(setq p2 (getpoint))
(command "_.LINE" p1 p2 "")
(princ)
)
A basic AutoLISP function that prompts the user for two points and draws a line between them in AutoCAD.
2
AutoLISP Loop to Draw Multiple Circles
(defun c:DrawCircles ()
(setq center (getpoint "\nSelect center point: "))
(setq radius 1)
(repeat 5
(command "_.CIRCLE" center radius)
(setq radius (+ radius 2))
)
(princ)
)
This AutoLISP script draws 5 circles with increasing radii at a fixed center point.
3
Draw Rectangle Using AutoLISP
(defun c:DrawRectangle ()
(setq p1 (getpoint "\nFirst corner: "))
(setq p2 (getpoint "\nOpposite corner: "))
(command "_.RECTANGLE" p1 p2)
(princ)
)
Prompts user for two corners and draws a rectangle.
4
Draw a Polyline in AutoLISP
(defun c:DrawPolyline ()
(setq pts '())
(prompt "\nPick points, press Enter to finish")
(while (setq pt (getpoint))
(setq pts (append pts (list pt)))
)
(command "_.PLINE" (apply 'append pts) "")
(princ)
)
Creates a polyline from user-specified points.
5
Draw Concentric Circles
(defun c:ConcentricCircles ()
(setq center (getpoint "\nCenter point: "))
(setq radius 2)
(repeat 5
(command "_.CIRCLE" center radius)
(setq radius (+ radius 2))
)
(princ)
)
Draws concentric circles with increasing radii.
6
Move Selected Objects
(defun c:MoveObjects ()
(setq ss (ssget))
(setq base (getpoint "\nBase point: "))
(setq target (getpoint "\nTarget point: "))
(command "_.MOVE" ss "" base target)
(princ)
)
Moves selected objects by a vector defined by two points.
7
Scale Selected Objects
(defun c:ScaleObjects ()
(setq ss (ssget))
(setq base (getpoint "\nBase point: "))
(setq factor (getreal "\nScale factor: "))
(command "_.SCALE" ss "" base factor)
(princ)
)
Scales objects by a user-defined factor.
8
Rotate Selected Objects
(defun c:RotateObjects ()
(setq ss (ssget))
(setq base (getpoint "\nBase point: "))
(setq angle (getangle base "\nRotation angle: "))
(command "_.ROTATE" ss "" base angle)
(princ)
)
Rotates selected objects around a base point by a specified angle.
9
Erase Selected Objects
(defun c:EraseObjects ()
(setq ss (ssget))
(command "_.ERASE" ss "")
(princ)
)
Deletes selected objects from the drawing.
10
Create Text at a Point
(defun c:CreateText ()
(setq pt (getpoint "\nInsertion point: "))
(setq txt (getstring "\nEnter text: "))
(command "_.TEXT" pt 1 0 txt)
(princ)
)
Prompts for a point and a string, and creates a text object.