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.