NCopyExtra

Short description

AutoCAD AutoLISP / Visual LISP tool for copying geometry from XREF drawings into the host drawing, with dialog-driven XREF selection, rectangle/window filtering, optional debug reporting, XREF layer-name cleanup, layer property transfer, and a classical nested-object copy mode.

Command:

NCopyExtra
NCopyExtraD
NCopyExtraW
NCopyExtraI
ClassicalNCopy

Description:

NCopyExtra is an AutoCAD AutoLISP utility designed to copy objects from attached XREF drawings into the current host drawing while preserving correct placement through transformation handling.

The main NCopyExtra command opens a DCL dialog first. From the dialog, the user can pick a rectangular selection area, identify or choose an XREF, filter the XREF list with wildcard text, select Crossing or Window mode, and control whether layer properties are copied, whether copied entities are placed on _hilfslinien, and whether the operation is wrapped in a single UNDO group.

The routine resolves the selected XREF path, opens the referenced drawing through ObjectDBX when needed, transforms the host selection rectangle into XREF-local coordinates, scans the XREF model space using bounding boxes, and copies the matching objects into the active drawing.

The included ClassicalNCopy command provides a direct one-by-one workflow using nentselp. It copies a picked nested object, applies the nested transformation matrix with vla-transformby, strips the XREF prefix from the layer name, creates the clean local layer when needed, and copies key layer properties from the XREF layer.

Helper function: (if any)​

Core helper functions include NCE:run, NCE:write-dcl, NCE:get-all-xrefs, NCE:filter-xrefs, NCE:pick-window-xref, NCE:find-xref-chain, NCE:make-dbx, NCE:open-doc, NCE:scan-xref, NCE:do-copy, NCE:strip-prefix, NCE:ensure-layer, NCE:ensure-hilfslinien-layer, NCE:get-uscale, NCE:world-to-local, NCE:make-fmat, NCE:rpt, and NCE:rpt-save.

Public commands are c:NCopyExtra, c:NCopyExtraD, c:NCopyExtraW, c:NCopyExtraI, and c:ClassicalNCopy.

Functionalities:

– Dialog-first workflow with Pick Rectangle, Pick XREF on Screen, XREF dropdown, wildcard filter, status feedback, and OK validation.
– Crossing and Window selection modes for copying only the XREF objects whose bounding boxes match the requested area.
– ObjectDBX-based XREF access, allowing the routine to scan the referenced DWG model space and copy matching objects into the current drawing.
– Coordinate transformation support for direct and nested XREFs, including world-to-local conversion, unit scaling, and matrix-based placement.
– Optional layer property transfer from XREF layers to local trimmed layers, including color, linetype, and lineweight.
– Optional placement of copied entities on the helper layer _hilfslinien.
– Optional single UNDO group around the copy operation.
– Debug/report mode through NCopyExtraD, with report text saved to a temporary TXT file.
– XREF locator workflow through NCopyExtraW, including preview boundary box and copy-all or rectangle-copy options.
– XREF coordinate and nesting diagnostic workflow through NCopyExtraI.
– ClassicalNCopy workflow for selecting and copying nested XREF objects one by one with nentselp.

Result:

The routine copies selected XREF geometry into the host AutoCAD drawing. Depending on the selected options, copied entities are either moved to _hilfslinien or assigned to clean local layer names where the XREF prefix has been removed. Layer properties can be transferred so the local drawing keeps the visual standards of the original XREF layers.

Images, animations etc.

Pixel

XAML code:

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:Autodesk.Windows;assembly=AdWindows">
    
<src:RibbonToolTip x:Key="NCopyExtra">
<src:RibbonToolTip.ExpandedContent>
<StackPanel>
<TextBlock Background="AntiqueWhite" TextAlignment="Left">
<Bold>Function Syntax: NCopyExtra</Bold>
<LineBreak/>
<Bold>Version: 1 Date: 13.10.2025</Bold>
<LineBreak/>
<LineBreak/>
<Hyperlink>AI+https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-ncopy-multiple-at-same-place-or-pause-the-ncopy-command/td-p/10932882</Hyperlink>
<LineBreak/>


<Bold><Run Foreground="DodgerBlue">Command name</Run></Bold><LineBreak/>
<Run>NCopyExtra — type </Run><Bold><Run Foreground="DarkRed">NCopyExtra</Run></Bold><Run> at the AutoCAD command line.</Run><LineBreak/>
<Run>Additional commands: </Run><Bold><Run Foreground="DarkRed">NCopyExtraD</Run></Bold><Run>, </Run><Bold><Run Foreground="DarkRed">NCopyExtraW</Run></Bold><Run>, </Run><Bold><Run Foreground="DarkRed">NCopyExtraI</Run></Bold><Run>, and </Run><Bold><Run Foreground="DarkRed">ClassicalNCopy</Run></Bold><Run>.</Run><LineBreak/>
<LineBreak/>

<Bold><Run Foreground="DodgerBlue">Description</Run></Bold><LineBreak/>
<Run>This AutoLISP / Visual LISP routine copies selected objects from an attached </Run><Bold><Run Foreground="DarkRed">XREF</Run></Bold><Run> into the current drawing.</Run><LineBreak/>
<Run>It uses a dialog-first workflow where the user can pick a rectangle, select or identify an XREF, choose Crossing or Window mode, and control copy options before the geometry is transferred.</Run><LineBreak/>
<Run>The copied objects are transformed into the host drawing position and can be placed either on </Run><Bold><Run Foreground="DarkRed">_hilfslinien</Run></Bold><Run> or onto a clean local layer name with the XREF prefix removed.</Run><LineBreak/>
<Run>It preserves the original object geometry and can match layer properties such as color, linetype, and lineweight from the original XREF layer.</Run><LineBreak/>
<LineBreak/>

<Bold><Run Foreground="DodgerBlue">Main DCL workflow</Run></Bold><LineBreak/>
<Run>🚀 The command </Run><Bold><Run Foreground="DarkRed">NCopyExtra</Run></Bold><Run> opens the dialog immediately.</Run><LineBreak/>
<Run>📐 The </Run><Bold><Run Foreground="DarkRed">Pick Rectangle on Screen</Run></Bold><Run> button closes the dialog, lets the user pick P1 and P2, then reopens the dialog with the coordinates filled in.</Run><LineBreak/>
<Run>🔍 The </Run><Bold><Run Foreground="DarkRed">Pick XREF on Screen</Run></Bold><Run> button helps identify an XREF graphically and confirms it in the XREF list.</Run><LineBreak/>
<Run>🧩 The dropdown lists all resolvable XREFs in the current drawing and supports a wildcard filter.</Run><LineBreak/>
<Run>📦 The user can choose </Run><Bold><Run Foreground="DarkRed">Crossing</Run></Bold><Run> or </Run><Bold><Run Foreground="DarkRed">Window</Run></Bold><Run> selection mode.</Run><LineBreak/>
<Run>⚙️ Options control layer property transfer, placement on </Run><Bold><Run Foreground="DarkRed">_hilfslinien</Run></Bold><Run>, and a single UNDO group.</Run><LineBreak/>
<LineBreak/>

<Bold><Run Foreground="DodgerBlue">User interaction</Run></Bold><LineBreak/>
<Run>• The user selects a host rectangle and an XREF before confirming the copy operation.</Run><LineBreak/>
<Run>• The OK button is enabled only after the rectangle and XREF selection are valid.</Run><LineBreak/>
<Run>• </Run><Bold><Run Foreground="DarkRed">NCopyExtraW</Run></Bold><Run> can zoom to the visible XREF area, draw a preview boundary box, and offer Copy All or Pick Rectangle options.</Run><LineBreak/>
<Run>• </Run><Bold><Run Foreground="DarkRed">NCopyExtraI</Run></Bold><Run> prints coordinate, XREF path, nesting-chain, bounding-box, and unit-scale diagnostics.</Run><LineBreak/>
<Run>• </Run><Bold><Run Foreground="DarkRed">ClassicalNCopy</Run></Bold><Run> lets the user repeatedly select nested objects one by one until Enter or Esc is pressed.</Run><LineBreak/>
<LineBreak/>

<Bold><Run Foreground="DodgerBlue">High-level workflow</Run></Bold><LineBreak/>
<Run>• Accesses the current AutoCAD document using </Run><Bold><Run Foreground="DarkRed">ActiveX / VLA / VLAX</Run></Bold><Run>.</Run><LineBreak/>
<Run>• Reads the XREF catalogue from the block table and filters valid external references.</Run><LineBreak/>
<Run>• Resolves direct or nested XREF placement using the block hierarchy and transformation matrices.</Run><LineBreak/>
<Run>• Opens the XREF drawing through </Run><Bold><Run Foreground="DarkRed">ObjectDBX</Run></Bold><Run> when required.</Run><LineBreak/>
<Run>• Converts the host drawing rectangle into XREF-local coordinates.</Run><LineBreak/>
<Run>• Scans XREF model space objects by bounding box using Crossing or Window logic.</Run><LineBreak/>
<Run>• Copies matching objects into the active drawing with </Run><Bold><Run Foreground="DarkRed">CopyObjects</Run></Bold><Run>.</Run><LineBreak/>
<Run>• Applies the correct transformation matrix with </Run><Bold><Run Foreground="DarkRed">vla-transformby</Run></Bold><Run> so the copied entities appear in the correct host location.</Run><LineBreak/>
<Run>• Optionally removes the XREF prefix from the original layer name, for example </Run><Bold><Run Foreground="DarkRed">_XREF|LayerName</Run></Bold><Run> becomes </Run><Bold><Run Foreground="DarkRed">LayerName</Run></Bold><Run>.</Run><LineBreak/>
<Run>• Ensures the destination layer exists, creating it when needed.</Run><LineBreak/>
<Run>• Copies key layer properties from the XREF layer to the clean local layer.</Run><LineBreak/>
<LineBreak/>

<Bold><Run Foreground="DodgerBlue">ClassicalNCopy mode</Run></Bold><LineBreak/>
<Run>• The user is repeatedly prompted to </Run><Bold><Run Foreground="DarkRed">select an object to copy</Run></Bold><Run>.</Run><LineBreak/>
<Run>• The routine continues in a loop until the user cancels selection or presses Enter.</Run><LineBreak/>
<Run>• It uses </Run><Bold><Run Foreground="DarkRed">nentselp</Run></Bold><Run> to select nested XREF objects and retrieve transformation context.</Run><LineBreak/>
<Run>• It reads the selected object entity data with </Run><Bold><Run Foreground="DarkRed">entget</Run></Bold><Run>, including the layer stored under DXF group code </Run><Bold><Run Foreground="DarkRed">8</Run></Bold><Run>.</Run><LineBreak/>
<Run>• It creates a new entity from the original entity list using </Run><Bold><Run Foreground="DarkRed">entmakex</Run></Bold><Run>.</Run><LineBreak/>
<Run>• It applies the nested selection matrix with </Run><Bold><Run Foreground="DarkRed">vla-transformby</Run></Bold><Run>.</Run><LineBreak/>
<Run>• It assigns the copied entity to </Run><Bold><Run Foreground="DarkRed">_hilfslinien</Run></Bold><Run> or to the trimmed local layer, depending on the saved option.</Run><LineBreak/>
<LineBreak/>

<Bold><Run Foreground="DodgerBlue">Functionalities</Run></Bold><LineBreak/>
<Run>✅ Dialog-driven XREF copying from rectangular selection windows.</Run><LineBreak/>
<Run>✅ Object duplication from XREF model space into the current host drawing.</Run><LineBreak/>
<Run>✅ Automatic XREF layer name cleanup.</Run><LineBreak/>
<Run>✅ Automatic creation of destination layers when needed.</Run><LineBreak/>
<Run>✅ Layer standards carry-over from the XREF layer to the local layer.</Run><LineBreak/>
<Run>✅ Optional placement of copied entities onto </Run><Bold><Run Foreground="DarkRed">_hilfslinien</Run></Bold><Run>.</Run><LineBreak/>
<Run>✅ Optional single UNDO group for safer editing.</Run><LineBreak/>
<Run>✅ Debug reporting with </Run><Bold><Run Foreground="DarkRed">NCopyExtraD</Run></Bold><Run>.</Run><LineBreak/>
<Run>✅ XREF location preview with </Run><Bold><Run Foreground="DarkRed">NCopyExtraW</Run></Bold><Run>.</Run><LineBreak/>
<Run>✅ Coordinate and nesting diagnostics with </Run><Bold><Run Foreground="DarkRed">NCopyExtraI</Run></Bold><Run>.</Run><LineBreak/>
<LineBreak/>

<Bold><Run Foreground="DodgerBlue">Important commands and calls highlighted</Run></Bold><LineBreak/>
<Run>• </Run><Bold><Run Foreground="DarkRed">nentselp</Run></Bold><Run> — interactive nested selection that provides transformation context.</Run><LineBreak/>
<Run>• </Run><Bold><Run Foreground="DarkRed">entget</Run></Bold><Run> — reads the original entity definition.</Run><LineBreak/>
<Run>• </Run><Bold><Run Foreground="DarkRed">entmakex</Run></Bold><Run> — creates a copied entity in the drawing database.</Run><LineBreak/>
<Run>• </Run><Bold><Run Foreground="DarkRed">CopyObjects</Run></Bold><Run> — copies scanned ObjectDBX objects into the active drawing.</Run><LineBreak/>
<Run>• </Run><Bold><Run Foreground="DarkRed">vla-transformby</Run></Bold><Run> — applies the transformation matrix for correct position and orientation.</Run><LineBreak/>
<Run>• </Run><Bold><Run Foreground="DarkRed">vla-item</Run></Bold><Run> and </Run><Bold><Run Foreground="DarkRed">vla-add</Run></Bold><Run> — read and create layers in the drawing.</Run><LineBreak/>
<Run>• </Run><Bold><Run Foreground="DarkRed">vla-put-Color</Run></Bold><Run>, </Run><Bold><Run Foreground="DarkRed">vla-put-LineType</Run></Bold><Run>, and </Run><Bold><Run Foreground="DarkRed">vla-put-Lineweight</Run></Bold><Run> — transfer layer properties.</Run><LineBreak/>
<Run>• </Run><Bold><Run Foreground="DarkRed">vla-put-layer</Run></Bold><Run> — assigns the copied entity to the target layer.</Run><LineBreak/>
<Run>• </Run><Bold><Run Foreground="DarkRed">setcfg</Run></Bold><Run> and </Run><Bold><Run Foreground="DarkRed">getcfg</Run></Bold><Run> — store and reload persistent NCopyExtra settings.</Run><LineBreak/>
<LineBreak/>

<Bold><Run Foreground="DodgerBlue">Operational notes and limitations</Run></Bold><LineBreak/>
<Run>⚠️ This routine depends on </Run><Bold><Run Foreground="DarkRed">Visual LISP ActiveX</Run></Bold><Run> and ObjectDBX functionality.</Run><LineBreak/>
<Run>⚠️ The XREF file path must be resolvable; unloaded, unresolved, overlay, or complex nested references may require diagnostics.</Run><LineBreak/>
<Run>⚠️ It copies database objects and applies transformations; complex custom/proxy entities may behave differently depending on object type and available object data.</Run><LineBreak/>
<Run>⚠️ The temporary DCL file is created in the AutoCAD temporary folder and deleted after use.</Run><LineBreak/>
<LineBreak/>

<Bold><Run Foreground="DodgerBlue">Use case</Run></Bold><LineBreak/>
<Run>Ideal for CAD and Civil 3D users who need to bring selected XREF geometry into the active drawing while keeping the placement correct and converting prefixed XREF layer names into clean local drawing layers.</Run><LineBreak/>
<LineBreak/>

<Bold><Run Foreground="Yellow">Tags</Run></Bold><LineBreak/>
<Run Foreground="Yellow">🏷️ AutoCAD, 🏷️ AutoLISP, 🏷️ Visual LISP, 🏷️ Civil 3D, 🏷️ XREF, 🏷️ Xref Copy, 🏷️ Nested Copy, 🏷️ ObjectDBX, 🏷️ Layer Cleanup, 🏷️ CAD Automation, 🏷️ DCL, 🏷️ NCopyExtra</Run><LineBreak/>


</TextBlock>
            
<Grid>
<Image Source="PNG" Stretch="Uniform"/>
</Grid>

<Grid>
<MediaElement
 Source="GIF"
 Stretch="Uniform"
 Visibility="Visible"/>
 </Grid>

</StackPanel>
</src:RibbonToolTip.ExpandedContent>
</src:RibbonToolTip>
</ResourceDictionary>



Share this page:

Leave a Reply

Page Tag: 🏷️ Xref Copy

  • NCopyExtra

    Short descriptionAutoCAD AutoLISP / Visual LISP tool for copying geometry from XREF drawings into the host drawing, with dialog-driven XREF selection, rectangle/window filtering, optional debug reporting, XREF layer-name cleanup, layer property transfer, and a classical nested-object copy mode. Command:NCopyExtra NCopyExtraD NCopyExtraW NCopyExtraI ClassicalNCopy Description:NCopyExtra is an AutoCAD AutoLISP utility designed to copy objects from attached…