Learn the basics of AutoCAD and More!

Lesson 5.07 – Creating Geometry with AutoLISP

🧱 Lesson 5.7 – Creating Geometry with AutoLISP

Automate the creation of LINE, CIRCLE, and RECTANGLE objects using both command and entmake.


πŸ“š What You’ll Learn

By the end of this lesson, you’ll be able to:

  • Draw basic objects using AutoLISP: lines, circles, and rectangles
  • Understand when to use command vs. entmake
  • Use entmake to directly define geometry without user prompts
  • Write reusable drawing routines with hardcoded or user-driven inputs

🧠 Why It Matters

Creating geometry with AutoLISP opens the door to automating repetitive drawing tasks. Whether you’re laying out blocks, adding detail, or batch-generating entities, knowing how to build geometry in code gives you power and speed inside AutoCAD.


πŸ› οΈ Tools You’ll Use

Tool / FunctionPurpose
commandInvokes native AutoCAD drawing commands
entmakeConstructs and inserts objects directly from DXF data
getpointCollects coordinates from the user
list, quoteConstructs points and entity data

🧭 Lesson Structure

1️⃣ Using the command Function

The command function simulates manual AutoCAD commands. It’s simple and mirrors user input.

Draw a Line Between Two Points

(defun c:drawline ()
(setq pt1 (getpoint "\nStart point: "))
(setq pt2 (getpoint "\nEnd point: "))
(command "LINE" pt1 pt2 "")
(princ)
)

Draw a Circle at a Point

(defun c:drawcircle ()
(setq center (getpoint "\nCenter point: "))
(setq radius (getreal "\nRadius: "))
(command "CIRCLE" center radius)
(princ)
)

Draw a Rectangle Using Two Points

(defun c:drawrect ()
(setq pt1 (getpoint "\nFirst corner: "))
(setq pt2 (getpoint "\nOpposite corner: "))
(command "RECTANGLE" pt1 pt2)
(princ)
)

βœ… Use the "" at the end of a command call to signal “Enter” or end of input.

2️⃣ Using entmake for DXF-Based Geometry

entmake allows you to create entities directly by supplying DXF group codes.

Draw a Line with Hardcoded Points

(entmake
(list
(cons 0 "LINE")
(cons 10 (list 0.0 0.0 0.0)) ; Start point
(cons 11 (list 100.0 100.0 0.0)) ; End point
)
)
Group CodeMeaningExample Value
0Entity type"LINE", "CIRCLE"
10Start point(list x y z)
11End point(list x y z)
40Radius (CIRCLE)25.0

Draw a Circle with entmake

(entmake
(list
(cons 0 "CIRCLE")
(cons 10 (list 50.0 50.0 0.0))
(cons 40 10.0)
)
)

🧠 Use entmake when you don’t need user interaction and want full control.

3️⃣ Command vs. entmake – When to Use What

ApproachProsUse When
commandSimple, readable, supports dynamic inputInteracting with user or invoking full commands
entmakePrecise, no dialog boxes, script-friendlyCreating geometry programmatically or in bulk

βœ… Lesson Checklist

TaskCompleted
Drew a line, circle, and rectangle using command☐
Created a circle and line using entmake☐
Understood DXF group codes used with entmake☐
Compared pros and cons of command vs. entmake☐

πŸ“Œ Quick Tips

TipWhy It Helps
Always include all required DXF codesMissing codes can cause invisible or bad entities
Use "" to finish command inputSimulates Enter in AutoCAD command stream
Wrap geometry in separate functionsEncourages reuse and debugging
Use command for flexibility, entmake for controlMatch the method to the job

🧩 Real-World Applications

Use CaseRecommended MethodWhy
Interactive line drawingcommandAllows real-time point selection
Title block layout toolentmakeFully automated and fixed layout
Batch geometry creationentmakeFaster and avoids prompts
User-guided circle toolscommandIntuitive and readable for input

πŸ“ Files and Resources

File / ResourceDescription
draw_shapes_command.lspRoutine using command to draw all 3 shapes
draw_shapes_entmake.lspRoutine using entmake with DXF codes
entmake_reference.docxDXF code cheat sheet for common geometry types

πŸ“– Review Table

FunctionUse CaseExample
commandSimulates AutoCAD command input(command "LINE" pt1 pt2 "")
entmakeCreates entities from DXF list(entmake (list (cons 0 "LINE") ...))
getpointGets point from user(getpoint "\\nStart point: ")
listCreate coordinate values(list 0.0 0.0 0.0)
consCreate key/value pair for DXF(cons 10 (list x y z))