Learn the basics of AutoCAD and More!

Lesson 5.10 – Automating Title Blocks with AutoLISP

πŸ—‚οΈ 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 and command

🧠 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

FunctionPurpose
commandInserts the block into the drawing
entgetRetrieves the block reference data
entnextSteps to the next entity (e.g., attached attributes)
entmodModifies attribute values
entupdForces 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 point
  • 1.0 = Scale X and Y
  • 0.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

TaskCompleted
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

TipWhy It Helps
Always test for the correct block nameAvoids inserting the wrong object
Attribute tag names are case-sensitive"DATE" is not the same as "date"
Use entnext carefullyAttributes appear sequentially after the block
Use entupd after entmodEnsures screen refresh

🧩 Real-World Applications

Use CaseAttribute Tag ExamplesPurpose
Insert & populate new sheetsSHEETNO, REV, DATEBatch drawing generation
Update old projectsPROJECT, CLIENT, DRAWNBYStandardize documentation
Customize templatesTITLE, DWGNO, SCALEAdapt blocks for specific jobs

πŸ“ Files and Resources

File / ResourceDescription
insert_titleblock.lspScript to insert a title block at origin
fill_attributes_example.lspScript to populate attributes for last inserted block
attribute_tags_template.docxEditable list of typical title block tags and uses

πŸ“– Review Table

FunctionDescriptionExample
commandInserts a block(command "INSERT" "TITLEBLOCK" '(0 0 0) ...)
entgetRetrieves entity data(entget ent)
entnextMoves to next entity (e.g., attribute)(entnext blk)
substReplaces value in DXF list(subst (cons 1 "John") (assoc 1 dxf) dxf)
entmodApplies the changes(entmod dxf)
entupdRefreshes the visual result(entupd ent)