Short description
Sort / Purpose: Copy nested objects from xrefs or blocks into the current drawing so they become local entities on local layers that mirror the xref layer properties.
• Scope: Works on objects selected with NENTSEL / NENTSELp, including items on xref layers like “_XREF|VG_KK”.
• Goal: Quickly “detach” geometry from xrefs by copying it out onto new local layers that inherit color, linetype, and lineweight from the original xref layer.
Command:
Command name: NCopyExtra
How to run: Load the LISP file, then type NCopyExtra in the command line and press Enter.
• Selection: Repeatedly pick nested objects (e.g. in xrefs or blocks) when prompted; press Enter to finish and exit the loop.
Description:
• Environment setup: Grabs the current AutoCAD application, active document, and layer table to manage layer creation and property copying.
• Nested selection: Uses NENTSELp to let you pick objects inside xrefs or block references, capturing both the picked entity and its transform matrix.
• Layer name read: Reads the original entity’s layer name (for example “_XREF|VG_KK”) from its DXF group 8 data.
• Xref prefix cleanup: Detects a “|” in the layer name and trims off the xref prefix so only the local layer name remains (e.g. turns “_XREF|VG_KK” into “VG_KK”).
• Entity cloning: Creates a new entity in the current space using ENTMAKEX with the original entity’s DXF data.
• Transform application: Applies the nested transform matrix returned by NENTSELp so the copied entity appears in the correct location and orientation in the current space.
• Layer object retrieval: Gets the full original layer object (including the xref prefix) from the layer table to read its visual properties.
• Local layer ensure: Checks if the trimmed local layer already exists; if not, creates it, otherwise reuses the existing local layer object.
• Property mirroring: Copies color, linetype, and lineweight from the xref layer object to the corresponding local layer, synchronizing their appearance.
• Layer reassignment: Assigns the newly created entity to the trimmed local layer name so it no longer resides on an xref layer.
• Loop behavior: Repeats the selection–copy–layer process for each picked object until you press Enter with no selection to end the command.
Helper function: (if any)
Core tools and functions used:
• vl-load-com: Enables COM / ActiveX access so VLA layer and entity properties can be read and written.
• vlax-get-acad-object: Retrieves the main AutoCAD application object.
• vla-get-ActiveDocument: Accesses the current drawing document where entities and layers live.
• vla-get-Layers: Returns the Layers collection used to query existing layers and add new ones.
• nentselp: Picks nested entities and returns both the entity name and the transformation matrix for proper world placement.
• entget: Reads DXF data from the picked entity to get its layer name and geometry definition.
• entmakex: Creates a new entity from the original entity’s DXF list in the active space.
• vlax-tmatrix: Converts the nentsel transformation list into a transformation matrix object usable by VLA.
• vla-transformby: Applies the nested transformation so the copy is correctly positioned and oriented.
• vla-item: Fetches specific Layer objects by name from the Layers collection (both original xref layer and local layer).
• vla-add: Creates a new layer when the trimmed local layer does not yet exist.
• vla-put-Color / LineType / Lineweight: Transfer visual properties from the xref layer to the local mirrored layer.
• vla-put-Layer: Assigns the copied entity to the desired local layer name.
Functionalities:
• Xref geometry extraction: Copies geometry out of xrefs or nested blocks into the current drawing space while preserving position and orientation.
• Layer name cleaning: Automatically strips the xref prefix from layer names so copied entities end up on clean local layers (e.g. “VG_KK” instead of “_XREF|VG_KK”).
• Local layer creation: Automatically creates missing local layers on the fly when they do not already exist in the drawing.
• Visual property sync: Mirrors color, linetype, and lineweight from the original xref layer to the local layer to maintain the same visual appearance.
• Entity relocation: New copies are placed directly on the local (non-xref) layer, making them independent from the xref reference.
• Multi-pick workflow: You can keep picking objects one after another and each one will be copied and re-layered until you press Enter to finish.
• Safe layer handling: Operates only on layers that actually exist and ensures new layers are properly initialized before use.
Result:
Result: Each picked nested object is duplicated into the current drawing as an independent entity on a clean local layer whose properties match the original xref layer.
• Independent geometry: The copied entities no longer depend on the xref; they are fully local and editable even if the xref is unloaded or detached.
• Clean layer structure: The drawing gets local layers (without xref prefixes) that visually match the xref layers, helping to standardize and simplify layer naming.
• Consistent appearance: Because color, linetype, and lineweight are cloned from the original xref layer, the copied entities look identical to what they were inside the xref.
• Controlled extraction: You decide interactively which pieces to pull from the xref or block, one pick at a time, instead of exploding or binding the entire reference.
Copy code:
Images, animations etc.
Log in to download.
Log in
Log in
Additional info:
Based on / Source code:
Open Website
Share this page:
Subscribe
Login
0 Comments
Oldest
Tags: CAD
Tags: CAD
