Function Syntax: delblocks Version: 1.0 Date: 20.06.2026 6:38:48PM http://www.lee-mac.com/deleteblocks.html short_description: | SEO Short Description 🚀 DeleteBlocks is an AutoCAD AutoLISP and DCL utility for deleting block definitions and their references from a DWG drawing. It helps CAD users inspect block names, review instance counts, filter block lists, select unused blocks, and remove unwanted block definitions faster. The main benefit is cleaner AutoCAD drawings, reduced block clutter, faster DWG maintenance, and better drawing cleanup control. command: | Main Command and Loading Method 🧰 Load the LISP file with APPLOAD or by using (load "DeleteBlocks.lsp"). Run DELBLOCKS to open the DCL block deletion dialog. The main AutoLISP entry point is c:delblocks. The target platform is AutoCAD and AutoCAD-based products that support AutoLISP, Visual LISP COM, and DCL dialogs. description: | Detailed Description 📘 DeleteBlocks scans the active AutoCAD drawing and builds a list of block definitions with detected instance counts. 🔍 The user starts DELBLOCKS, reviews the generated dialog, filters block names, changes sort direction, selects one or more block definitions, and confirms deletion. 🧹 The program removes matching block references from model space, paper space, and block definitions where possible, then attempts to delete the selected block definitions. 🧠 The dialog remembers filter text, horizontal scroll position, sort direction, dialog width, and list height through Windows registry settings. 🔴 Important: this is a destructive cleanup command because selected block names are deleted globally from the current drawing where AutoCAD allows deletion. helper_function: | Helper Logic 🚀 Command entry point - c:delblocks builds the block list and launches the DCL dialog immediately. 🔍 Block data scanner - LM:delblocks:buildblockdata reads the block table and counts INSERT references for each block name. 🧩 Effective block name support - LM:blockname uses EffectiveName where available for better dynamic block handling. 📊 Instance count display - Rows are displayed as block name plus count, such as BOLT (12x) or BOLT (unused). 🔍 Filter logic - _applyfilter filters block names with wcmatch and case-insensitive comparison. 🔄 Sort logic - _checksortdir switches the list between AZ and ZA ordering. 📌 DCL dialog generator - LM:delblocks:listbox writes a unique temporary DCL file to avoid stale dialog conflicts. 🧠 Registry persistence - LM:delblocks:regread and LM:delblocks:regsave store user interface settings under HKCU\Software\LM_DelBlocks. 🟧 Select unused helper - _purgeunused selects zero-instance block definitions for cleanup. 🔴 Nested block warning - LM:delblocks:nestedmap detects blocks used inside other blocks and asks before deletion. 🔒 Layer lock handling - LM:deleteblocks unlocks locked layers temporarily, deletes references, deletes definitions where possible, and restores locks. 🧹 Undo grouping - LM:startundo and LM:endundo wrap delete operations in an AutoCAD undo mark. functionalities: | Functionalities 🚀 Open block deletion manager - runs DELBLOCKS to display a DCL list of block deletion candidates. 🔢 Show block instance counts - displays how many references each block name has in the drawing database. 🔍 Filter block names - narrows the list by text for faster block cleanup. 🔄 Sort A-Z or Z-A - changes list order for large DWG block libraries. 📌 Select multiple blocks - allows multi-select deletion from one dialog. 🧹 Select unused blocks - automatically selects zero-instance blocks for purge-style cleanup. 🟧 Select all and deselect all - supports fast bulk review workflows. 📊 Horizontal scroll simulation - uses a DCL slider to inspect long block names. 🔴 Nested block protection warning - warns when a selected block is used inside another block definition. 🔒 Locked layer support - temporarily unlocks layers and restores lock state after deletion. 🧠 Persistent user settings - remembers filter, scroll, sort direction, and dialog size. 🔴 Global block deletion - removes matching block references and attempts to delete the selected block definitions from the active DWG. result: | Final Result ✅ The final result is a practical AutoCAD block cleanup command that centralizes block review, filtering, instance counting, unused block selection, nested block checking, and block deletion. It reduces repetitive manual block cleanup work, improves DWG hygiene, and supports cleaner AutoCAD and Civil 3D production drawings. additional_info: | Additional Notes 🔴 Destructive behavior - selected block names are removed globally where possible, not only from manually selected block references. 🔒 Undo note - the delete process is wrapped in an AutoCAD undo mark, but users should save or back up important drawings before bulk deletion. 📌 Protected blocks - xrefs, anonymous blocks, dependent definitions, layout records, or other special definitions may be skipped or may fail to delete depending on AutoCAD rules. 🧩 Dynamic block note - effective names are used where available, which is useful when counting or deleting dynamic block references. 📘 Configuration - user interface settings are stored in the Windows registry under HKCU\Software\LM_DelBlocks.