Learn the basics of AutoCAD and More!

Lesson 5.09 – Modifying Objects with AutoLISP

✏️ Lesson 5.9 – Modifying Objects with AutoLISP

Learn how to use entget, entmod, and entupd to change layers, colors, and positions of existing geometry.


πŸ“š What You’ll Learn

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

  • Retrieve entity data using entget
  • Modify properties such as layer, color, or coordinates using entmod
  • Use entupd to visually refresh updated entities
  • Write scripts that adjust object attributes programmatically

🧠 Why It Matters

AutoCAD drawings often need cleanup, reorganization, or formatting. AutoLISP lets you automate those edits at scaleβ€”changing thousands of entities with a single routine. Whether adjusting layers, colors, or geometry, entmod puts you in control.


πŸ› οΈ Tools You’ll Use

FunctionPurpose
entgetRetrieves an entity’s DXF data
entmodSubmits modified data back into the drawing
entupdForces a visual update of modified entities
assocFinds a DXF group in a list
substSubstitutes a new item into a list

🧭 Lesson Structure

1️⃣ Retrieve Entity Data with entget

Use entget to get an entity’s DXF structure:

(setq ent (car (entsel "\nSelect an object: ")))
(setq data (entget ent))

This returns a list of key-value pairs, like:

((0 . "LINE") (8 . "0") (62 . 256) (10 0.0 0.0 0.0) ...)

2️⃣ Modify a Property with subst

You can change a value in the DXF list using subst.

Change Color to Red (1):

(setq data (subst (cons 62 1) (assoc 62 data) data))
CodeDescriptionValue Type
8LayerString
62Color Index (ACI)Integer
10Start pointList of floats

Change Layer:

(setq data (subst (cons 8 "MyLayer") (assoc 8 data) data))

3️⃣ Apply Changes with entmod and entupd

Once modified, commit the changes:

(entmod data)
(entupd ent)
  • entmod applies the data to the drawing
  • entupd forces the object to visually update

βœ… Lesson Checklist

TaskCompleted
Selected and retrieved entity data using entget☐
Used assoc to inspect properties☐
Modified properties using subst and entmod☐
Used entupd to force screen refresh☐

πŸ“Œ Quick Tips

TipWhy It Helps
Always test if entsel returned a valuePrevents errors if the user cancels selection
Use (assoc code list) to retrieve valuesClean and readable way to find DXF entries
Use (subst ...) carefullyEnsure you’re replacing a matching pair

🧩 Real-World Applications

ScenarioWhat to ModifyWhy
Assign new color schemeChange 62 valuesVisual clarity
Reorganize by layerChange 8 valuesBetter structure
Realign geometryModify 10, 11 coordinatesFix design or layout issues

πŸ“ Files and Resources

File / ResourceDescription
modify_color_layer.lspRoutine to change layer and color of selected objects
entget_cheatsheet.docxCommon DXF codes for entity inspection/modification
property_update_template.lspCode scaffold for modifying any entity property

πŸ“– Review Table

FunctionDescriptionExample
entgetGet entity DXF data(entget ent)
entmodApply modified DXF list(entmod data)
entupdRefresh entity on screen(entupd ent)
assocFind a code/value in a list(assoc 8 data)
substReplace a code/value in a list(subst (cons 8 "MyLayer") (assoc 8 data) data)