π§± 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 / Function | Purpose |
---|---|
command | Invokes native AutoCAD drawing commands |
entmake | Constructs and inserts objects directly from DXF data |
getpoint | Collects coordinates from the user |
list , quote | Constructs 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 Code | Meaning | Example Value |
---|
0 | Entity type | "LINE" , "CIRCLE" |
10 | Start point | (list x y z) |
11 | End point | (list x y z) |
40 | Radius (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
Approach | Pros | Use When |
---|---|---|
command | Simple, readable, supports dynamic input | Interacting with user or invoking full commands |
entmake | Precise, no dialog boxes, script-friendly | Creating geometry programmatically or in bulk |
β Lesson Checklist
Task | Completed |
---|---|
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
Tip | Why It Helps |
---|---|
Always include all required DXF codes | Missing codes can cause invisible or bad entities |
Use "" to finish command input | Simulates Enter in AutoCAD command stream |
Wrap geometry in separate functions | Encourages reuse and debugging |
Use command for flexibility, entmake for control | Match the method to the job |
π§© Real-World Applications
Use Case | Recommended Method | Why |
---|---|---|
Interactive line drawing | command | Allows real-time point selection |
Title block layout tool | entmake | Fully automated and fixed layout |
Batch geometry creation | entmake | Faster and avoids prompts |
User-guided circle tools | command | Intuitive and readable for input |
π Files and Resources
File / Resource | Description |
---|---|
draw_shapes_command.lsp | Routine using command to draw all 3 shapes |
draw_shapes_entmake.lsp | Routine using entmake with DXF codes |
entmake_reference.docx | DXF code cheat sheet for common geometry types |
π Review Table
Function | Use Case | Example |
---|---|---|
command | Simulates AutoCAD command input | (command "LINE" pt1 pt2 "") |
entmake | Creates entities from DXF list | (entmake (list (cons 0 "LINE") ...)) |
getpoint | Gets point from user | (getpoint "\\nStart point: ") |
list | Create coordinate values | (list 0.0 0.0 0.0) |
cons | Create key/value pair for DXF | (cons 10 (list x y z)) |