CopyBlock

Short description

Sort / Purpose: Copy a block reference, give it a new block name, and optionally force it and its contents onto a chosen layer while optionally deleting the original reference.Scope: Works on a single selected block reference and creates a new block definition plus a retargeted (or copied) reference.Goal: Provide an interactive way to duplicate and rename blocks, with an optional “+Layer” mode to standardize content layers and an option to remove the original block reference automatically.
copyblockchangelayer 000

Command:

Command name: CopyBlockChangeLayer How to run: Load the LISP file, then type CopyBlockChangeLayer in the command line and press Enter.Selection: You are prompted to select a single block reference that is not on a locked layer.Dialog: After selection, a dialog opens with mode selection, new block name, optional layer tools, and a “Delete Initial Block” toggle.

Description:

Block picking: Prompts you to pick a block reference and verifies that it is an INSERT and not on a locked layer before continuing.Default naming: Proposes a default new block name based on the original name (Base_1, Base_2, and so on) that is guaranteed to be unique among existing blocks.Dialog modes: The dialog offers two modes via radio buttons: “Copy Rename Block” and “Copy Rename Block + Layer”.Name input: Allows you to type a custom new block name and validates it against existing block names and symbol name rules.Layer tools (+Layer mode): When the “Copy Rename Block + Layer” mode is active, a layer filter box, a layer list, and a “Pick from drawing” button become active so you can choose a target layer interactively.Delete toggle: A “Delete Initial Block” toggle (default on) controls whether the original reference is deleted after the new, renamed copy is created and retargeted.Definition cloning: Uses ObjectDBX to copy the original block definition to a temporary database, rename it there, and copy the renamed definition back into the active drawing as a new block.Reference handling: Keeps a handle to the original reference, and in copy mode creates a duplicate reference, then repoints the active (possibly copied) reference to the newly created block definition.Layer enforcement (+Layer mode): If a layer is chosen, sets the new block reference to that layer and optionally forces all geometry inside the new block definition to that layer and ByLayer properties.Original cleanup: If the “Delete Initial Block” option is enabled, the original reference is deleted, leaving only the new renamed (and possibly re-layered) reference in place.Error and cancel: Handles invalid names, ObjectDBX failures, and user cancellation with informative messages and clean exit.

Helper function: (if any)​

Helper functions:LM:AcadMajorVersion: Returns the major AutoCAD version number to construct the correct ObjectDBX interface string.LM:CopyObjects: Wraps VLA CopyObjects to copy block definitions between the active drawing and the temporary ObjectDBX document.LM:ForceBlockContentsByLayer: For a given block name and layer, sets all entities in that block definition to that layer, color ByLayer, linetype ByLayer, and lineweight ByLayer.LM:BuildDialogAndGet: Dynamically builds the DCL file, populates the layer list, manages filter and selection, handles “Pick from drawing”, reads all user choices, and returns new name, layer, mode, and delete flag.LM:RenameBlockReference: Core engine called by the command; handles selection, ObjectDBX cloning and renaming, retargeting block reference, applying layer mode, and optionally deleting the original reference. Key system and VLA calls:vla-get-ActiveDocument / vla-get-Blocks: Access the active drawing and its block table.vla-getInterfaceObject: Creates the ObjectDBX AxDbDocument used to clone and rename block definitions safely.vla-Copy / vla-Delete: Duplicates and optionally removes the original block reference depending on user choices.vlax-get-or-create-object / vlax-release-object: Manage external COM objects and ensure they are properly released.

Functionalities:

Copy and rename in one step: Creates a new block definition, copies geometry, and assigns a new name while leaving the original definition intact.Two working modes: Simple “Copy Rename Block” mode, or an extended “Copy Rename Block + Layer” mode with full layer control and filtering.Interactive layer selection: In +Layer mode, you can filter layer names, select from a list, or pick any object in the drawing to adopt its layer.Content normalization: Optionally forces all entities in the new block definition to a single layer and ByLayer display properties for consistent behavior.Safe naming strategy: Automatically proposes a unique default name and prevents invalid or duplicate block names from being used.Delete original toggle: You can decide whether the original block reference is kept or automatically deleted after the new one is created and linked.Locked layer protection: Rejects block references placed on locked layers to avoid unintended edits in protected areas.Version aware: Uses the AutoCAD version to connect to the correct ObjectDBX interface for reliable operation across releases.

Result:

Result: A new block definition is created with a new name, the chosen reference is retargeted to this definition, and optionally placed on a selected layer with its contents forced ByLayer, while the original reference can be removed automatically.New block identity: You obtain a separate, uniquely named block that can be edited or managed independently from the original definition.Layer controlled copy: In +Layer mode, the new block reference and its internal geometry conform to a single layer standard, improving visibility and plotting control.Clean replacement: With “Delete Initial Block” enabled, the original reference is removed and replaced by the newly named copy in the same location.Predictable behavior: The new block reacts as expected to layer changes and ByLayer properties, making it easier to integrate into existing layer standards. Copy code: Copy CopyBlockChangeLayer LISP

Images, animations etc.

Pixel

Additional info:

Share this page:

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Tags: Blocks
Tags: Blocks
0
Would love your thoughts, please comment.x
()
x