Function Syntax: CopyBlock_CB Version: 1 Date: 09.10.2025 AI+https://www.lee-mac.com/copyblock.html short_description: | SEO Description ๐Ÿš€ CopyBlockChangeLayer is an AutoCAD AutoLISP and DCL utility for copying a selected block reference, creating a renamed block definition, optionally changing its layer, and optionally deleting the original block reference. The main benefit is faster AutoCAD block management, cleaner DWG layer organization, reusable block variants, and fewer manual CAD cleanup steps. command: | Main Command and Loading Method ๐Ÿงฐ Load the LISP with APPLOAD or through the AutoCAD startup suite. Run CopyBlockChangeLayer to open the Copy / Rename Block workflow. The main entry point is c:CopyBlockChangeLayer, which calls LM:RenameBlockReference in copy mode. The target platform is AutoCAD and AutoCAD-based verticals with Visual LISP, ActiveX COM, DCL dialogs, ObjectDBX, block references, and layer tables. description: | Detailed Description ๐Ÿ“˜ The program asks the user to select one block reference in the drawing. It proposes a new block name based on the original effective block name and an available numeric suffix. The DCL dialog lets the user choose Copy Rename Block or Copy Rename Block + Layer. In simple mode, the selected block reference is copied, a renamed block definition is created, and the copied reference is retargeted to the new definition. In layer mode, the copied reference can be moved to a selected layer, and entities inside the new block definition can be forced to that same layer. The layer list excludes xref-dependent layers, supports filtering, and includes a Pick from drawing button to read a layer from an existing object. The routine uses ObjectDBX and vla-CopyObjects to copy, rename, and re-import block definitions. Important: the Delete Initial Block toggle is enabled by default, so the original selected block reference is deleted after the copy is created unless the user disables it. helper_function: | Helper Logic ๐Ÿš€ Command wrapper - c:CopyBlockChangeLayer starts the tool and calls the rename-copy workflow. ๐Ÿง  AutoCAD version helper - LM:AcadMajorVersion reads ACADVER and builds the correct ObjectDBX interface name. ๐Ÿงฉ Object copy engine - LM:CopyObjects uses a Visual LISP safe array and vla-CopyObjects to move block definitions between databases. ๐ŸŽจ Block content layer cleanup - LM:ForceBlockContentsByLayer sets internal block entities to the selected layer and resets color, linetype, and lineweight to ByLayer. ๐Ÿ“ DCL dialog builder - LM:BuildDialogAndGet writes the temporary Copy / Rename Block dialog with modes, name input, layer list, filter, pick-layer button, and delete toggle. ๐Ÿ” Layer filtering - update-layer-list filters drawing layers with wcmatch and excludes xref-dependent layer names containing the pipe character. ๐Ÿ“Œ Pick layer from drawing - entsel lets the user click an object and read its layer from DXF group code 8. ๐Ÿ”’ Selection safety - LM:RenameBlockReference accepts only INSERT entities and rejects locked-layer block references. ๐Ÿท๏ธ Name validation - snvalid checks the proposed block name and prevents duplicate block table names. ๐Ÿ”ด Original reference deletion - vla-Delete removes the original reference when Delete Initial Block is enabled. functionalities: | Functionalities ๐Ÿš€ Copy and rename a block reference - creates an independent renamed block definition from the selected block. ๐Ÿท๏ธ Automatic name proposal - suggests names such as BlockName_1, BlockName_2, and higher available suffixes. ๐Ÿงฉ Two workflow modes - supports simple copy and copy with layer control. ๐ŸŽจ Layer assignment - moves the copied block reference to the chosen drawing layer. ๐Ÿ” Layer filter list - helps users quickly find the correct AutoCAD layer in the dialog. ๐Ÿ“Œ Pick layer from drawing - reads a layer from an existing object instead of requiring manual typing. ๐Ÿงน ByLayer cleanup - updates new block definition contents to the chosen layer and resets display properties to ByLayer. ๐Ÿ”ด Delete initial block option - automatically removes the original selected block reference when enabled. ๐Ÿ”’ Validation checks - rejects non-block entities, locked-layer blocks, invalid block names, and duplicate block names. ๐Ÿ“ Reference geometry preservation - keeps the copied reference placement, rotation, and scale by using vla-Copy. ๐Ÿงฐ ObjectDBX block definition workflow - renames the copied block definition through an ObjectDBX database. ๐ŸŸข DCL interface - provides a compact dialog for faster AutoCAD block editing. result: | Final Result โœ… The final result is a faster AutoCAD block editing workflow where one selected block reference becomes a copied and renamed independent block variant. The tool improves DWG cleanup, layer standardization, CAD productivity, block library management, and drawing production consistency. additional_info: | Important Notes and Limitations ๐Ÿ”ด Delete Initial Block is enabled by default and deletes the original selected block reference after the copied reference is created. ๐Ÿงฉ In layer mode, the code modifies the new copied block definition contents, not the original block definition. ๐Ÿ“Œ Xref-dependent layers are excluded from the selectable layer list. ๐Ÿง  The code requires Visual LISP COM and AutoCAD ObjectDBX support. ๐Ÿ“˜ The tool manages AutoCAD block references and layers; it does not modify Civil 3D ProfileView, SectionView, Alignment, bands, labels, surfaces, corridors, or styles.