Short description
๐๐ Move all AutoCAD XREF block references onto clean XREF layers using either one shared _XREF layer or individual 0-XREF_ layers.

Command:
๐ Primary command: XRefs2LayersOptions
๐ Option 1: XRefsTo_Xref / X2_XREF โ moves all detected XREF inserts to one layer named _XREF.
๐ Option 2: XRefsToLayers / X2L โ moves each XREF insert to its own layer using the 0-XREF_ prefix.
๐ช Dialog helper: radioX2LDCL creates a small DCL option dialog for choosing the workflow.
Description:
๐ XRefs2Layers is an AutoCAD AutoLISP utility for organizing external reference inserts by layer.
๐ The tool scans the current drawing for XREF block definitions, ignores names matching *TBLOCK*, finds matching INSERT references, and moves those references to controlled XREF layers.
๐งญ The user can run a dialog-based workflow with XRefs2LayersOptions or run direct commands for a specific mode. One mode places every XREF on a shared _XREF layer, while the other mode creates separate 0-XREF_ layers for clearer drawing management.
๐ก๏ธ The routine uses ActiveX layer handling, undo marks, locked-layer recovery logic, and a final alert report showing how many XREFs were moved to each target layer.
Helper function: (if any)โ
๐ช writeX2LDCL โ writes the temporary DCL dialog for the two XREF layer options.
๐ radioX2LDCL โ loads the DCL, remembers the last selected option, and returns the selected workflow.
๐งญ XRefs2LayersOptions โ main option selector that launches the selected XREF layer command.
๐ XRefsToLayers / X2L โ creates or uses 0-XREF_ layers and moves each XREF to its matching named layer.
๐ XRefsTo_Xref / X2_XREF โ creates or uses the shared _XREF layer and moves all XREF inserts there.
๐ก๏ธ Error handlers โ close undo marks safely and report unexpected errors without interrupting normal cancel behavior.
Functionalities:
๐ XREF detection โ scans AutoCAD Blocks collection for definitions where IsXRef is true.
๐งน TBLOCK exclusion โ skips XREF names matching *TBLOCK* to avoid processing title-block style references.
๐ช DCL option dialog โ provides a simple radio-button interface for choosing the layer organization mode.
๐ Per-XREF layer mode โ moves XREF inserts to uppercase layers named with the 0-XREF_ prefix.
๐ฆ Shared layer mode โ moves all XREF inserts to one standard _XREF layer.
๐งฑ Layer auto-create โ creates missing destination layers automatically.
๐ Locked-layer handling โ temporarily unlocks the current layer when required so the XREF can be moved.
โฉ๏ธ Undo mark support โ wraps processing in an undo mark for safer drawing edits.
๐ Move report โ displays a summary alert showing counts by target layer.
โ๏ธ Session memory โ remembers the last selected radio option during the active AutoCAD session.
๐ซ Zero-XREF warning โ alerts the user when no XREFs are found in the drawing.
Result:
โ The result is a cleaner AutoCAD drawing where XREF references are organized on predictable layers.
๐ CAD teams can quickly isolate, freeze, lock, audit, or plot XREF content by using either one shared _XREF layer or separate 0-XREF_ layers.
๐ The final alert gives immediate feedback about how many XREF references were moved to each layer.
Images, animations etc.




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="XRefs2Layers">
<src:RibbonToolTip.ExpandedContent>
<StackPanel>
<TextBlock Background="AntiqueWhite" TextAlignment="Left">
<Bold>Function Syntax: XRefs2LayersOptions / X2L / XRefsToLayers / X2_XREF / XRefsTo_Xref</Bold>
<LineBreak/>
<Bold>Version: 1.0 Date: 20.06.2026 6:39:04PM</Bold>
<LineBreak/>
<Hyperlink>AI+https://www.cadtutor.net/forum/topic/20566-xrefstolayerslsp-move-xrefs-to-corresponding-layers/</Hyperlink>
<LineBreak/>
<Bold><Run Foreground="DodgerBlue">Function Syntax: XRefs2Layers</Run></Bold><LineBreak/>
<Bold><Run Foreground="Orange">Version: 1.0</Run></Bold><LineBreak/>
<LineBreak/>
<Bold><Run Foreground="DodgerBlue">๐ SEO Friendly Description</Run></Bold><LineBreak/>
<Run Foreground="White">๐ XRefs2Layers is an AutoCAD AutoLISP tool for organizing external references by moving XREF insert references onto clean, predictable XREF layers.</Run><LineBreak/>
<Run Foreground="LimeGreen">๐ It improves CAD layer management, XREF visibility control, drawing cleanup, Civil 3D production organization, and DWG audit workflows.</Run><LineBreak/>
<Run Foreground="White">๐ช The command includes a DCL option dialog so the user can choose between a shared XREF layer workflow and a per-XREF layer workflow.</Run><LineBreak/>
<LineBreak/>
<Bold><Run Foreground="DodgerBlue">๐ Main Commands</Run></Bold><LineBreak/>
<Run Foreground="White">๐ช Run </Run><Bold><Run Foreground="Orange">XRefs2LayersOptions</Run></Bold><Run Foreground="White"> to open the option dialog.</Run><LineBreak/>
<Run Foreground="White">๐ Run </Run><Bold><Run Foreground="Orange">XRefsToLayers</Run></Bold><Run Foreground="White"> or </Run><Bold><Run Foreground="Orange">X2L</Run></Bold><Run Foreground="White"> to move each XREF to its own </Run><Bold><Run Foreground="LimeGreen">0-XREF_<XREF name></Run></Bold><Run Foreground="White"> layer.</Run><LineBreak/>
<Run Foreground="White">๐ฆ Run </Run><Bold><Run Foreground="Orange">XRefsTo_Xref</Run></Bold><Run Foreground="White"> or </Run><Bold><Run Foreground="Orange">X2_XREF</Run></Bold><Run Foreground="White"> to move all detected XREF inserts to one shared </Run><Bold><Run Foreground="LimeGreen">_XREF</Run></Bold><Run Foreground="White"> layer.</Run><LineBreak/>
<LineBreak/>
<Bold><Run Foreground="LimeGreen">๐งฉ Functionalities</Run></Bold><LineBreak/>
<Run Foreground="White">๐ </Run><Bold><Run Foreground="LimeGreen">XREF scan</Run></Bold><Run Foreground="White"> - scans the AutoCAD Blocks collection and detects block definitions where </Run><Bold><Run Foreground="Orange">IsXRef</Run></Bold><Run Foreground="White"> is true.</Run><LineBreak/>
<Run Foreground="White">๐งน </Run><Bold><Run Foreground="LimeGreen">TBLOCK exclusion</Run></Bold><Run Foreground="White"> - ignores XREF names matching </Run><Bold><Run Foreground="Orange">*TBLOCK*</Run></Bold><Run Foreground="White"> to avoid processing title-block style references.</Run><LineBreak/>
<Run Foreground="White">๐ช </Run><Bold><Run Foreground="LimeGreen">Dialog selection</Run></Bold><Run Foreground="White"> - creates a temporary DCL window with radio buttons for choosing the target layer method.</Run><LineBreak/>
<Run Foreground="White">๐ </Run><Bold><Run Foreground="LimeGreen">Per-XREF layer mode</Run></Bold><Run Foreground="White"> - creates organized layers using the </Run><Bold><Run Foreground="Orange">0-XREF_</Run></Bold><Run Foreground="White"> prefix and the XREF name.</Run><LineBreak/>
<Run Foreground="White">๐ฆ </Run><Bold><Run Foreground="LimeGreen">Shared layer mode</Run></Bold><Run Foreground="White"> - places every detected XREF insert on the common </Run><Bold><Run Foreground="Orange">_XREF</Run></Bold><Run Foreground="White"> layer.</Run><LineBreak/>
<Run Foreground="White">๐งฑ </Run><Bold><Run Foreground="LimeGreen">Automatic layer creation</Run></Bold><Run Foreground="White"> - creates missing destination layers before moving the XREF insert references.</Run><LineBreak/>
<Run Foreground="White">๐ </Run><Bold><Run Foreground="LimeGreen">Locked-layer recovery</Run></Bold><Run Foreground="White"> - temporarily unlocks the current layer when a layer change fails because of a locked layer state.</Run><LineBreak/>
<Run Foreground="White">โฉ๏ธ </Run><Bold><Run Foreground="LimeGreen">Undo mark support</Run></Bold><Run Foreground="White"> - wraps edits in an AutoCAD undo mark for safer production use.</Run><LineBreak/>
<Run Foreground="White">๐ </Run><Bold><Run Foreground="LimeGreen">Result report</Run></Bold><Run Foreground="White"> - displays an alert summary with the number of XREF inserts moved to each layer.</Run><LineBreak/>
<Run Foreground="White">โ๏ธ </Run><Bold><Run Foreground="LimeGreen">Session memory</Run></Bold><Run Foreground="White"> - remembers the last selected option while the AutoCAD session remains open.</Run><LineBreak/>
<LineBreak/>
<Bold><Run Foreground="DodgerBlue">โ
Practical Result</Run></Bold><LineBreak/>
<Run Foreground="White">โ
The drawing becomes easier to manage because all XREF inserts are placed on predictable layers for visibility control, plotting, locking, freezing, and CAD standard review.</Run><LineBreak/>
<Run Foreground="LimeGreen">๐ This is useful for AutoCAD users, Civil 3D teams, CAD managers, drafting technicians, and production environments with many external references.</Run><LineBreak/>
<LineBreak/>
<Bold><Run Foreground="DarkRed">โ ๏ธ Important Notes</Run></Bold><LineBreak/>
<Run Foreground="White">โ ๏ธ The routine changes the layer assignment of XREF INSERT references in the active drawing.</Run><LineBreak/>
<Run Foreground="White">โ ๏ธ It does not modify the external source DWG files referenced by the XREFs.</Run><LineBreak/>
<Run Foreground="White">โ ๏ธ The per-XREF workflow can lock created XREF layers when the lock prompt is confirmed.</Run><LineBreak/>
<Run Foreground="White">โ ๏ธ Review project CAD standards before running this tool on production drawings.</Run><LineBreak/>
</TextBlock>
<Grid>
<Image Source="Image_000.jpg" Stretch="Uniform"/>
</Grid>
<Grid>
<Image Source="Image_001.jpg" Stretch="Uniform"/>
</Grid>
<Grid>
<Image Source="Image_002.jpg" Stretch="Uniform"/>
</Grid>
<Grid>
<Image Source="Image_003.jpg" Stretch="Uniform"/>
</Grid>
</StackPanel>
</src:RibbonToolTip.ExpandedContent>
</src:RibbonToolTip>
</ResourceDictionary>

Leave a Reply
You must be logged in to post a comment.