Function Syntax: DelUnusedBlocks N/A short_description: ๐Ÿš€ DelUnusedBlocks is an AutoCAD AutoLISP and DCL cleanup utility for detecting and deleting unused block definitions from the active DWG drawing. ๐Ÿงน It scans the block table, removes inserted blocks from the candidate list, excludes xrefs, layout blocks, anonymous blocks, and dependent records, then shows only deletable unused block names. โœ… The main benefit is faster AutoCAD drawing cleanup, reduced DWG clutter, better block library management, and improved CAD standards control. command: ๐Ÿงฐ Load the LISP with APPLOAD or an AutoCAD startup loading method. ๐Ÿš€ Run DelUnusedBlocks to open the generated DCL dialog named Delete Unused Blocks. ๐Ÿ“„ Main source file: DelUnusedBlocks_DCL.lsp. ๐Ÿ’พ Settings are saved in DelUnusedBlocks.cfg using ROAMABLEROOTPREFIX, DWGPREFIX, TEMPPREFIX, or the current folder as fallback locations. description: ๐Ÿ“˜ This AutoCAD cleanup tool helps the user delete unused block definitions through a DCL multi-select dialog instead of manual block table inspection. ๐Ÿ” The program uses tblnext on the BLOCK table and checks DXF group code 70 to exclude non-deletable records. ๐Ÿง  It removes block names that still have inserted references by using ssget "_X" with an INSERT filter. ๐Ÿ“‹ The dialog lists unused block definitions, supports multi-selection, Select All, Select None, and an optional confirmation toggle. ๐Ÿงน Selected unused definitions are deleted with ActiveX database calls such as vla-item and vla-delete. Important: this is a cleanup command that deletes selected unused block definitions from the DWG block table. helper_function: ๐Ÿš€ Command entry point - c:DelUnusedBlocks starts the scan, DCL dialog, settings read, user selection, and deletion workflow. ๐Ÿ” Unused block detection - DUB:block-inserted-p checks whether a block name still has INSERT references in the drawing. ๐Ÿ”’ Protected block filtering - DXF 70 flag mask skips anonymous blocks, xrefs, externally dependent blocks, xref-dependent definitions, resolved xrefs, and layout blocks. ๐Ÿ“‹ DCL generator - DUB:write-dcl and DUB:dcl-text write a temporary DCL file with a multi-select list, selection buttons, confirmation toggle, Delete, and Cancel. ๐Ÿง  Index and name mapping - DUB:names->index-string and DUB:index-string->names converts saved block names to DCL list indexes and back. ๐Ÿงน Deletion engine - DUB:delete-selected and DUB:delete-block delete selected unused block definitions using AutoCAD ActiveX methods. โš ๏ธ Confirmation prompt - DUB:yes-p asks Yes or No before deletion when confirmation is enabled. ๐Ÿ’พ Persistent settings - DUB:read-cfg and DUB:write-state save confirmation, last selected names, and dialog coordinates in DelUnusedBlocks.cfg. ๐Ÿ” Safe COM wrapper - LM:catchapply uses vl-catch-all-apply to reduce hard failures when COM operations fail. functionalities: ๐Ÿš€ Dedicated AutoCAD cleanup command - runs DelUnusedBlocks for unused block definition cleanup. ๐Ÿ” Automatic unused block scan - finds block definitions that are not inserted in the active DWG. ๐Ÿ”’ Protected record exclusion - skips xrefs, dependent blocks, layout records, and anonymous/system definitions. ๐Ÿ“‹ Generated DCL interface - shows unused blocks in a multi-select dialog. ๐ŸŸข Select All - marks every detected unused block definition. โšช Select None - clears the DCL selection for manual picking. โš ๏ธ Confirmation option - can ask the user before deleting selected block definitions. ๐Ÿงน Delete selected unused blocks - removes chosen unused definitions from the block table. ๐Ÿ’พ Save user settings - remembers dialog position, confirmation state, and previous selections. ๐Ÿ“Š Command-line report - prints deleted names and the total number of deleted unused blocks. ๐Ÿ” Clean cancel behavior - preserves settings and exits without deleting when cancelled. result: โœ… The final result is a cleaner AutoCAD DWG with selected unused block definitions removed from the drawing database. ๐Ÿš€ The tool improves block cleanup speed, CAD standard maintenance, drawing audit preparation, DWG performance hygiene, and project handover quality. additional_info: ๐Ÿ”ด Destructive action: selected unused block definitions are deleted, so save or back up important drawings before running cleanup. ๐Ÿ”’ Inserted blocks are protected because the routine excludes block definitions that still have matching INSERT references. โš ๏ธ The code does not create a custom undo mark. AutoCAD standard undo behavior may still apply depending on command history. ๐Ÿ“Œ In complex dynamic block or anonymous block workflows, review the detected list carefully before deleting. ๐Ÿงฐ Requires AutoCAD Visual LISP and COM support through vl-load-com.