Learn the basics of AutoCAD and More!

Lesson 5.18 – Title Block Filler

🏁 Lesson 5-18 – Capstone Project: Title Block Filler + Layer Manager with AutoLISP

Combine your AutoLISP skills to create a complete, reusable routine that inserts a title block, fills attributes, and creates standard layers with assigned colors.


📚 What You’ll Build

By the end of this lesson, you will have created a tool that:

  • Prompts the user for job-specific information (e.g., project name, date, drawn by)
  • Inserts a title block block reference into the drawing
  • Fills out the block’s attributes using that input
  • Creates a predefined set of standard layers with color assignments

This is a full workflow that can be reused on all your future CAD projects.


🧠 Why It Matters

Instead of repeating the same manual steps each time you start a new drawing, this routine will:

  • Reduce human error
  • Standardize your setups across multiple jobs or team members
  • Serve as a foundation for more advanced toolkits (e.g., sheet sets, batch plotters)

🛠️ Tools You’ll Use

Tool / ConceptPurpose
getstring, getint, getpointGet user input interactively
commandInsert block and call built-in commands
entmod, entget, entupdModify attribute values of inserted blocks
entmake or commandCreate layers and assign properties
Error handling (*error*)Ensure a clean environment if canceled

🧭 Lesson Structure

1️⃣ Get User Input

Prompt for the details needed to fill out the title block:

(setq proj (getstring T "\\nEnter Project Name: "))
(setq date (getstring T "\\nEnter Date: "))
(setq drawnby (getstring T "\\nEnter Drafter Name: "))

2️⃣ Insert the Title Block

Insert a predefined block using the command function. Ensure the block exists in the drawing or attach it via WBLOCK/INSERT:

(command "._-INSERT" "TITLEBLOCK" '(0 0 0) 1 1 0)
(setq blk (entlast))

3️⃣ Fill in the Block Attributes

Loop through the block’s attributes and update based on tag:

(setq ent (entnext blk))
(while ent
(setq tag (cdr (assoc 2 (entget ent))))
(cond
((= tag "PROJECT") (entmod (subst (cons 1 proj) (assoc 1 (entget ent)) (entget ent))))
((= tag "DATE") (entmod (subst (cons 1 date) (assoc 1 (entget ent)) (entget ent))))
((= tag "DRAWNBY") (entmod (subst (cons 1 drawnby) (assoc 1 (entget ent)) (entget ent)))))
(entupd ent)
(setq ent (entnext ent))
)

4️⃣ Create Standard Layers

Use a list of layer names with color codes to automate creation:

(setq layers '(("TEXT" 7) ("DIM" 2) ("DETAILS" 1) ("HATCH" 8) ("TITLE" 3)))

(foreach lay layers
(if (not (tblsearch "LAYER" (car lay)))
(command "._-layer" "m" (car lay) "c" (cadr lay) "" "")
)
)

5️⃣ Wrap in a Safe Command with Cleanup

Use error handling to restore settings after the routine runs or if it fails:

(defun c:startjob ( / *error* oldsnap proj date drawnby blk ent tag layers lay olderror )

(setq oldsnap (getvar "OSMODE"))
(defun my-error (msg)
(prompt (strcat "\\nError: " msg))
(setvar "OSMODE" oldsnap)
(setq *error* olderror)
(princ)
)
(setq olderror *error* *error* my-error)

;; 1. Input
(setq proj (getstring T "\\nEnter Project Name: "))
(setq date (getstring T "\\nEnter Date: "))
(setq drawnby (getstring T "\\nEnter Drafter Name: "))

;; 2. Insert Title Block
(command "._-INSERT" "TITLEBLOCK" '(0 0 0) 1 1 0)
(setq blk (entlast))

;; 3. Fill Attributes
(setq ent (entnext blk))
(while ent
(setq tag (cdr (assoc 2 (entget ent))))
(cond
((= tag "PROJECT") (entmod (subst (cons 1 proj) (assoc 1 (entget ent)) (entget ent))))
((= tag "DATE") (entmod (subst (cons 1 date) (assoc 1 (entget ent)) (entget ent))))
((= tag "DRAWNBY") (entmod (subst (cons 1 drawnby) (assoc 1 (entget ent)) (entget ent)))))
(entupd ent)
(setq ent (entnext ent))
)

;; 4. Create Layers
(setq layers '(("TEXT" 7) ("DIM" 2) ("DETAILS" 1) ("HATCH" 8) ("TITLE" 3)))
(foreach lay layers
(if (not (tblsearch "LAYER" (car lay)))
(command "._-layer" "m" (car lay) "c" (cadr lay) "" "")
)
)

;; 5. Cleanup
(setvar "OSMODE" oldsnap)
(setq *error* olderror)
(princ)
)

Project Checklist

StepCompleted
Defined user input prompts
Inserted a block using command
Fetched and updated attribute tags
Created standard layers with assigned colors
Handled errors and cleaned up environment

📁 Files and Resources

File / ResourceDescription
capstone_titleblock.lspFull working LISP routine
titleblock_template.dwgBlock reference with PROJECT, DATE, and DRAWNBY attributes
capstone_checklist.docxPrintable version of the project checklist