LayoutNum

Short description

  • Provides a DCL dialog to batch rename layouts using sequential numbering with optional prefix, suffix, and zero-padding, with filtering and preview.
  • Supports in-dialog Apply and multi-level Undo without calling AutoCAD UNDO from DCL callbacks, to avoid stability issues.
layoutnum 000

Command:

  • Commands: LAYOUTNUM, _LAYOUTNUM, LayoutNum

Description:

  • Builds a unique DCL dialog definition at runtime and lists layouts with a wildcard filter, optionally including Model in the list as a non-renamable entry.
  • Allows selecting multiple layouts, choosing ordering by tab order or alphabetical, and defining rename parameters: starting number, width (zero-padding), prefix, suffix, and optional auto-resolve for name conflicts.
  • Displays a preview list showing Old => New names before applying changes; preview refreshes when selection or options change.
  • Applies renaming using ActiveX by setting each layout object name, wrapped in a safe undo mark for editor-level undo grouping, while also recording rename frames for the dialog’s own manual undo stack.
  • Implements Undo inside the dialog by replaying stored rename frames in reverse to restore old names, avoiding the AutoCAD UNDO command inside DCL callbacks.
  • Persists the last-used UI values (filter, numbering, prefix/suffix, order, auto-resolve, include model) so the next run starts with the prior settings.

Helper function: (if any)​

  • LayoutNum:WriteDCL builds a unique dialog name and writes the full DCL string to a temporary file, returning the file path and dialog name.
  • LayoutNum:LayoutsTabOrder collects layout objects with their tab order and returns a sorted list used for display and renaming sequence.
  • LayoutNum:RebuildDisplay applies the filter and ordering, rebuilds the layout list, preserves selection, and refreshes the preview.
  • LayoutNum:GetSelectedItems maps list box indices to the underlying layout entries for consistent selection handling.
  • LayoutNum:ComputeRenamePlan generates the proposed new names based on start, pad, prefix, suffix, order, and conflict policy, marking Model as non-renamable.
  • LayoutNum:ValidateBeforeRename validates selection and numeric inputs and checks name uniqueness and conflicts when auto-resolve is disabled.
  • LayoutNum:ApplyRename performs renames, records a frame of (object old new) for manual undo, refreshes lists, and updates defaults for convenience.
  • LayoutNum:DoUndo restores the last rename frame in reverse order to avoid collisions and keeps selection on restored names after refresh.
  • _StartUndo and _EndUndo manage VLA undo marks safely without invoking the UNDO command inside DCL callbacks.
  • LayoutNum:Cleanup unloads the dialog and deletes the temporary DCL file to prevent leftovers across runs.
  • c:LAYOUTNUM, c:_LAYOUTNUM, c:LayoutNum are safe command entry points calling LayoutNum:Run.

Functionalities:

  • Wildcard filter with a dedicated Apply Filter action that rebuilds the displayed list without renaming anything.
  • Multi-select layouts with Select All and Select None shortcuts and a live status indicator showing shown and selected counts.
  • Preview panel showing proposed renames as Old => New, with a Refresh Preview button and auto-refresh on option changes.
  • Renaming options including starting number, zero-padding width, prefix, suffix, order mode (tab order or alphabetical), and auto-resolve for conflicts by appending -1, -2, and so on.
  • Non-destructive handling of Model when included: it can be listed but is blocked from renaming and triggers validation alerts if selected for rename.
  • Bottom controls: Apply renames and keeps dialog open, Undo restores prior rename sets, OK renames and closes, Cancel closes without applying a new rename.
  • Safety rule avoids calling AutoCAD UNDO from DCL callbacks and instead uses a manual undo stack, while still grouping changes with VLA undo marks.
  • Persists last-used settings across runs for faster repeat usage.

Result:

  • On Apply, selected layouts are renamed immediately according to the preview plan, the dialog stays open, and Undo becomes available for rollback of the last rename operation.
  • On Undo, the most recent rename frame is reverted and the selection is restored to the reverted layout names; supports multi-level undo until the stack is empty.
  • On OK, performs the rename then closes the dialog, persisting the current UI settings for the next run.
  • On Cancel or close, no new rename is applied by this action and the dialog exits after capturing settings and cleaning up the temporary DCL file.
  • If validation fails, shows an alert explaining the issue and prevents renaming until corrected.
  • If no paper-space layouts exist, prints a message and exits without opening the dialog.

Images, animations etc.

layoutnum 000
layoutnum 001
layoutnum 002
layoutnum 003
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="LayoutNum">
<src:RibbonToolTip.ExpandedContent>
<StackPanel>
<TextBlock Background="AntiqueWhite" TextAlignment="Left">
<Bold>Function Syntax: LayoutNum</Bold>
<LineBreak/>
<Bold>Version: 2 Date: 24.12.2025</Bold>
<LineBreak/>
<LineBreak/>
<Hyperlink>AI+https://www.cadtutor.net/forum/topic/14298-tabsortlsp/</Hyperlink>
<LineBreak/>
<Bold><Foreground Color="DarkRed">LayoutNum</Foreground> — Layout Numbering and Renaming Utility</Bold><LineBreak/><LineBreak/>
<Foreground Color="Gray">This program will prompt the user with a dialog to filter, select, preview, and rename drawing layouts (paper space tabs), using a controlled numbering scheme.</Foreground><LineBreak/><LineBreak/>

<Bold><Foreground Color="DarkRed">How to Run</Foreground></Bold><LineBreak/>
<Foreground Color="DarkRed">Commands:</Foreground> <Foreground Color="Red">LAYOUTNUM</Foreground>, <Foreground Color="Red">_LAYOUTNUM</Foreground>, <Foreground Color="Red">LayoutNum</Foreground><LineBreak/>
<Foreground Color="Gray">Running any of these commands opens the Layout Numbering dialog.</Foreground><LineBreak/><LineBreak/>

<Bold><Foreground Color="DarkRed">What the User Must Do</Foreground></Bold><LineBreak/>
• <Foreground Color="Gray">Optionally enter a wildcard filter using</Foreground> <Foreground Color="Red">*</Foreground> <Foreground Color="Gray">and</Foreground> <Foreground Color="Red">?</Foreground> <Foreground Color="Gray">to narrow the layout list.</Foreground><LineBreak/>
• <Foreground Color="Gray">Select one or more layouts from the list (multi-select).</Foreground><LineBreak/>
• <Foreground Color="Gray">Enter rename parameters:</Foreground> <Foreground Color="DarkRed">Starting Number</Foreground>, <Foreground Color="DarkRed">Width</Foreground>, <Foreground Color="DarkRed">Prefix</Foreground>, <Foreground Color="DarkRed">Suffix</Foreground>.<LineBreak/>
• <Foreground Color="Gray">Review the</Foreground> <Foreground Color="DarkRed">Preview (Old to New)</Foreground> <Foreground Color="Gray">before committing changes.</Foreground><LineBreak/><LineBreak/>

<Bold><Foreground Color="DarkRed">Primary Functionalities</Foreground></Bold><LineBreak/>
• <Foreground Color="DarkRed">Filter layouts by wildcard pattern</Foreground><Foreground Color="Gray">:</Foreground> <Foreground Color="Gray">Apply Filter rebuilds the visible list using patterns such as</Foreground> <Foreground Color="Red">A*</Foreground> <Foreground Color="Gray">or</Foreground> <Foreground Color="Red">Sheet??</Foreground>.<LineBreak/>
• <Foreground Color="DarkRed">Multi-select layout targeting</Foreground><Foreground Color="Gray">:</Foreground> <Foreground Color="Gray">The list supports selecting multiple layouts for batch renaming.</Foreground><LineBreak/>
• <Foreground Color="DarkRed">Select All and Select None</Foreground><Foreground Color="Gray">:</Foreground> <Foreground Color="Gray">Quickly select every visible layout or clear the selection.</Foreground><LineBreak/>
• <Foreground Color="DarkRed">Preview before rename</Foreground><Foreground Color="Gray">:</Foreground> <Foreground Color="Gray">Shows a calculated mapping of each selected layout name to the proposed new name.</Foreground><LineBreak/>
• <Foreground Color="DarkRed">Batch rename with numbering</Foreground><Foreground Color="Gray">:</Foreground> <Foreground Color="Gray">Renames selected layouts to</Foreground> <Foreground Color="DarkRed">Prefix</Foreground><Foreground Color="Gray"> plus a sequential number plus</Foreground> <Foreground Color="DarkRed">Suffix</Foreground>.<LineBreak/>
• <Foreground Color="DarkRed">Zero padding control</Foreground><Foreground Color="Gray">:</Foreground> <Foreground Color="Gray">Width controls numeric padding, such as</Foreground> <Foreground Color="Red">01</Foreground> <Foreground Color="Gray">or</Foreground> <Foreground Color="Red">001</Foreground>.<LineBreak/>
• <Foreground Color="DarkRed">Ordering control</Foreground><Foreground Color="Gray">:</Foreground> <Foreground Color="Gray">Numbering can follow</Foreground> <Foreground Color="DarkRed">Tab Order</Foreground> <Foreground Color="Gray">or</Foreground> <Foreground Color="DarkRed">Alphabetical</Foreground> <Foreground Color="Gray">order.</Foreground><LineBreak/>
• <Foreground Color="DarkRed">Automatic conflict resolution</Foreground><Foreground Color="Gray">:</Foreground> <Foreground Color="Gray">Optionally appends</Foreground> <Foreground Color="Red">-1</Foreground><Foreground Color="Gray">,</Foreground> <Foreground Color="Red">-2</Foreground><Foreground Color="Gray">, and so on, if a generated name already exists.</Foreground><LineBreak/>
• <Foreground Color="DarkRed">Include Model option</Foreground><Foreground Color="Gray">:</Foreground> <Foreground Color="Gray">Model can be shown in the list, but it is flagged as</Foreground> <Foreground Color="Red">cannot rename</Foreground> <Foreground Color="Gray">and will block applying changes if selected.</Foreground><LineBreak/><LineBreak/>

<Bold><Foreground Color="DarkRed">Dialog Buttons and Actions</Foreground></Bold><LineBreak/>
• <Foreground Color="Red">Apply Filter</Foreground><Foreground Color="Gray">:</Foreground> <Foreground Color="Gray">Applies the wildcard filter and refreshes the visible layout list without renaming.</Foreground><LineBreak/>
• <Foreground Color="Red">Refresh Preview</Foreground><Foreground Color="Gray">:</Foreground> <Foreground Color="Gray">Recomputes the Old to New mapping from the current selection and rename settings.</Foreground><LineBreak/>
• <Foreground Color="Red">Apply</Foreground><Foreground Color="Gray">:</Foreground> <Foreground Color="Gray">Performs the renaming immediately and keeps the dialog open.</Foreground><LineBreak/>
• <Foreground Color="Red">Undo</Foreground><Foreground Color="Gray">:</Foreground> <Foreground Color="Gray">Reverts the most recent Apply or OK rename operation using a safe internal rename history.</Foreground><LineBreak/>
• <Foreground Color="Red">OK</Foreground><Foreground Color="Gray">:</Foreground> <Foreground Color="Gray">Performs the renaming and closes the dialog.</Foreground><LineBreak/>
• <Foreground Color="Red">Cancel</Foreground><Foreground Color="Gray">:</Foreground> <Foreground Color="Gray">Closes the dialog without performing a new rename action.</Foreground><LineBreak/><LineBreak/>

<Bold><Foreground Color="DarkRed">Important Behaviors and Constraints</Foreground></Bold><LineBreak/>
• <Foreground Color="Red">Model layout cannot be renamed</Foreground><Foreground Color="Gray">:</Foreground> <Foreground Color="Gray">If Model is included and selected, renaming is blocked to prevent invalid operations.</Foreground><LineBreak/>
• <Foreground Color="DarkRed">Undo is manual and safe</Foreground><Foreground Color="Gray">:</Foreground> <Foreground Color="Gray">Undo does not rely on AutoCAD UNDO command calls during the dialog, avoiding ARX exceptions.</Foreground><LineBreak/>
• <Foreground Color="DarkRed">No forced exit</Foreground><Foreground Color="Gray">:</Foreground> <Foreground Color="Gray">The dialog remains open after Apply so the user can apply multiple rename passes.</Foreground><LineBreak/>
• <Foreground Color="Gray">User settings persist between runs (filter, numbering, width, prefix, suffix, options).</Foreground><LineBreak/><LineBreak/>

<Bold><Foreground Color="DarkRed">Typical Use Case Example</Foreground></Bold><LineBreak/>
• <Foreground Color="Gray">Filter:</Foreground> <Foreground Color="Red">*</Foreground> <Foreground Color="Gray">to show all layouts.</Foreground><LineBreak/>
• <Foreground Color="Gray">Select layouts:</Foreground> <Foreground Color="DarkRed">Layout1</Foreground> <Foreground Color="Gray">and</Foreground> <Foreground Color="DarkRed">Layout2</Foreground>.<LineBreak/>
• <Foreground Color="Gray">Set:</Foreground> <Foreground Color="DarkRed">Starting Number</Foreground> <Foreground Color="Red">1</Foreground><Foreground Color="Gray">,</Foreground> <Foreground Color="DarkRed">Width</Foreground> <Foreground Color="Red">2</Foreground><Foreground Color="Gray">,</Foreground> <Foreground Color="DarkRed">Prefix</Foreground> <Foreground Color="Red">aaa_</Foreground><Foreground Color="Gray">, Suffix blank.</Foreground><LineBreak/>
• <Foreground Color="Gray">Preview shows:</Foreground> <Foreground Color="Red">Layout1 => aaa_01</Foreground> <Foreground Color="Gray">and</Foreground> <Foreground Color="Red">Layout2 => aaa_02</Foreground>.<LineBreak/>
• <Foreground Color="Gray">Press</Foreground> <Foreground Color="Red">Apply</Foreground> <Foreground Color="Gray">to rename without closing, or</Foreground> <Foreground Color="Red">OK</Foreground> <Foreground Color="Gray">to rename and close.</Foreground><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>



Additional info:

Share this page:

Leave a Reply

Page Tag: 🏷️ Paper Space

  • LayoutNum

    Short description Provides a DCL dialog to batch rename layouts using sequential numbering with optional prefix, suffix, and zero-padding, with filtering and preview. Supports in-dialog Apply and multi-level Undo without calling AutoCAD UNDO from DCL callbacks, to avoid stability issues. Command: Commands: LAYOUTNUM, _LAYOUTNUM, LayoutNum Description: Builds a unique DCL dialog definition at runtime and…

  • LockAllVp

    Short description Tags: Layouts, Paper Space, Viewports, DCL, Dialog_UI, Lisp, CAD, Clipboard Suggested tags not in list: ObjectARX, COM_Automation, Stability, Undo_Stack Command: • LOCKALLVP Open the dialog to lock or unlock viewports in selected layouts. • LockAllVp Alias command to run the same dialog workflow. • _LOCKALLVP Underscore alias for macro use. Description: This tool…

  • Zoom Extend

    Short description LZE summary LZE opens a DCL selection dialog for Layouts, then runs Zoom Extents in Paper Space on the selected layouts after the dialog closes. Key stability rule The zoom action is executed after the dialog closes to avoid UI timing issues. Command: Command LZE Runs Zoom Extents on selected layouts in Paper…

  • Zoom Window

    Short description LZW summary LZW opens a DCL selection dialog for Layouts, then prompts for a window and runs Zoom Window in Paper Space on the selected layouts after the dialog closes. Key stability rule The zoom action is executed after the dialog closes to avoid UI timing issues. Command: Command LZW Runs Zoom Window…

  • FreezeLayersInVP

    Short description Shows a DCL dialog to filter and multi-select layers, then freezes the selected layers in the current viewport using VPLAYER. Supports filtering by Current layers, Xref layers, or Current_and_Xref, with an optional Xref picker and a fixed-width “faux columns” layer list. Command: Commands: FreezeLayersInVP and alias FLVP Description: Builds an embedded DCL file…

  • TitleBlocksTools

    Short description Title Blocks Tools – Unified Menu System Comprehensive dialog-based interface for exporting and updating titleblock attributes via CSV with integrated help, file management, and reload utilities. Command: Commands: TitleBlocksTools, EXPTBCSV_EXPORT, UTB2 Description: This integrated toolset combines CSV export and import functionality for titleblock attribute management: Main Menu Dialog provides radio button selection between…

  • Change Background Color

    Short description Changes AutoCAD’s model/paper background color using presets and keeps cursor/track/snap colors readable. Includes a dialog (DCL) with Apply/OK/Cancel and can restore the original colors if you cancel. Command: Command: c:BG Opens a DCL-based “Background Changer” dialog allowing you to pick a background color preset and apply it to Model and/or Paper space. Description:…