ποΈ Lesson 5-10 β Automating Title Blocks with AutoLISP
Learn how to insert a block with attributes and fill in its values automatically.
π What Youβll Learn
By the end of this lesson, youβll be able to:
- Insert a block containing attributes using AutoLISP
- Supply values for each attribute programmatically
- Automate repetitive title block updates across sheets
- Understand how attribute tags work with
entmake
andcommand
π§ Why It Matters
Title blocks are vital for identifying drawing detailsβbut filling them in manually across dozens of sheets is inefficient. AutoLISP makes it possible to insert and populate title blocks with a single command, reducing errors and saving time.
π οΈ Tools Youβll Use
Function | Purpose |
---|---|
command | Inserts the block into the drawing |
entget | Retrieves the block reference data |
entnext | Steps to the next entity (e.g., attached attributes) |
entmod | Modifies attribute values |
entupd | Forces drawing update |
π§ Lesson Structure
1οΈβ£ Prerequisite: Block with Attributes
Your title block must already be defined in the drawing (or as an external .DWG) and must contain attributesβtext fields tied to tags like "DRAWNBY"
, "DATE"
, "PROJECT"
.
2οΈβ£ Insert the Block Using command
Example inserting a block named "TITLEBLOCK"
at the origin:
(command "INSERT" "TITLEBLOCK" '(0 0 0) 1.0 1.0 0.0)
(0 0 0)
= Insertion point1.0
= Scale X and Y0.0
= Rotation angle
β Use double quotes around block name if it contains spaces.
3οΈβ£ Fill in Attributes
After insertion, use entnext
to walk through attached attributes.
(defun c:filltitleblock ( / blk ent tag val )
(setq blk (entlast)) ; assume last inserted is the block
(setq ent (entnext blk)) ; move to first attribute
(while ent
(setq tag (cdr (assoc 2 (entget ent)))) ; tag name
(cond
((= tag "DRAWNBY") (entmod (subst (cons 1 "Jane D.") (assoc 1 (entget ent)) (entget ent))))
((= tag "DATE") (entmod (subst (cons 1 "2025-05-29") (assoc 1 (entget ent)) (entget ent))))
((= tag "PROJECT") (entmod (subst (cons 1 "Warehouse Reno") (assoc 1 (entget ent)) (entget ent))))
)
(entupd ent)
(setq ent (entnext ent)) ; next attribute
)
(prompt "\\nTitle block attributes updated.")
(princ)
)
β Lesson Checklist
Task | Completed |
---|---|
Inserted a block with command | β |
Verified it has attributes with defined TAGs | β |
Used entnext to step through attached attributes | β |
Replaced attribute values using subst and entmod | β |
π Quick Tips
Tip | Why It Helps |
---|---|
Always test for the correct block name | Avoids inserting the wrong object |
Attribute tag names are case-sensitive | "DATE" is not the same as "date" |
Use entnext carefully | Attributes appear sequentially after the block |
Use entupd after entmod | Ensures screen refresh |
π§© Real-World Applications
Use Case | Attribute Tag Examples | Purpose |
---|---|---|
Insert & populate new sheets | SHEETNO , REV , DATE | Batch drawing generation |
Update old projects | PROJECT , CLIENT , DRAWNBY | Standardize documentation |
Customize templates | TITLE , DWGNO , SCALE | Adapt blocks for specific jobs |
π Files and Resources
File / Resource | Description |
---|---|
insert_titleblock.lsp | Script to insert a title block at origin |
fill_attributes_example.lsp | Script to populate attributes for last inserted block |
attribute_tags_template.docx | Editable list of typical title block tags and uses |
π Review Table
Function | Description | Example |
---|---|---|
command | Inserts a block | (command "INSERT" "TITLEBLOCK" '(0 0 0) ...) |
entget | Retrieves entity data | (entget ent) |
entnext | Moves to next entity (e.g., attribute) | (entnext blk) |
subst | Replaces value in DXF list | (subst (cons 1 "John") (assoc 1 dxf) dxf) |
entmod | Applies the changes | (entmod dxf) |
entupd | Refreshes the visual result | (entupd ent) |