Function Syntax: RenameLayer Version: 1.1 Date: 20.06.2026 6:38:54PM AI+https://www.cadtutor.net/forum/topic/68804-layer-rename-lisp-routine-issue/ Command name RenameLayer (type RenameLayer at the AutoCAD command line) Description This routine opens a custom dialog that lets the user batch rename layers based on search, remove, replace, prefix, suffix, optional all-caps conversion, and optional auto-merge behavior. Prerequisites • Requires Visual LISP COM support via (vl-load-com). • Uses Express Tools functions such as acet-ui-progress and acet-str-replace, so Express Tools should be available. User interaction • The user interacts with a DCL dialog named LayerRename. • The dialog collects criteria such as: • Text to search for in layer names. • Prefix and suffix to add. • String to remove. • Replace and With strings. • Toggle for Apply All Caps. • Toggle for Auto Merge Layers after Remove. • The user clicks OK to execute, or Cancel to exit without changes. High-level workflow • Creates a temporary DCL file (LayerRename.dcl) using vl-filename-mktemp and writes the dialog definition to disk. • Loads and displays the dialog using load_dialog, new_dialog, and start_dialog. • Reads user input via multiple action_tile callbacks. • Builds a list of drawing layers via ai_table and filters them: • Excludes layer 0. • If a search string is provided, selects only layers containing that string. • Shows a progress meter using acet-ui-progress. • For each target layer, computes a new name by applying the enabled transformations in sequence. • Renames layers using AutoCAD command calls via vl-cmdf to -rename and optionally -laymrg. • Wraps changes in a single undo group using vla-StartUndoMark and vla-EndUndoMark. • Cleans up by deleting the temporary DCL file and restoring system variables. Functionalities • Filters layers by a user-provided substring (or processes all layers except 0 if no substring is given). • Adds a prefix to the layer name. • Adds a suffix to the layer name. • Removes an arbitrary substring from the layer name using vl-string-subst. • Replaces one substring with another using acet-str-replace. • Optionally converts the final name to all caps (Apply All Caps toggle). • Optionally performs layer merge when the computed name already exists, using -laymrg. Transformation order used to build the new layer name • Starting name is the current layer name from the filtered list. • If Remove String is set, remove that substring first. • If Replace fields are set, apply Replace to With next. • If Prefix is set, add prefix next. • If Suffix is set, add suffix last. • If Apply All Caps is enabled, convert to uppercase at rename time. Validation and safeguards • Replace fields validation: if the user fills only one of Replace or With, it shows an alert and restarts the command. • If no matching layers are found for the search text, it alerts No Matching Text Found and restarts. • Excludes layer 0 from processing. • Uses an internal error handler to restore settings and delete the temporary DCL file on failure or cancel. Important commands and calls highlighted LRN_dialog — writes the DCL dialog definition to a temporary file. load_dialog and new_dialog — loads the DCL and instantiates the dialog. action_tile — captures user inputs from dialog controls. ai_table — retrieves layer names from the drawing layer table. acet-ui-progress — displays progress during layer processing. vl-cmdf "-rename" "la" — renames layers programmatically. vl-cmdf "-laymrg" — merges layers when enabled and when the destination layer exists. vla-StartUndoMark and vla-EndUndoMark — wraps the operation in a single undo step. Operational notes and limitations • If Auto Merge is enabled and the target name already exists, the routine attempts to merge the source layer into the destination layer using -laymrg. • If Auto Merge is disabled, and the target name already exists, the routine will not merge; it relies on rename behavior and existence checks to decide the path. • The dialog label indicates case sensitivity; however, the search uses vl-string-search which is case-sensitive, and the Apply All Caps toggle affects the final rename casing. • The routine creates and deletes a temporary DCL file each run; if file permissions restrict temp file creation, the dialog cannot load. Description 🧱 RenameLayer is an AutoCAD and Civil 3D AutoLISP utility for batch renaming local drawing layers through a custom DCL dialog. 🔎 The tool is SEO-focused for AutoCAD layer management, Civil 3D layer cleanup, DWG standardization, layer renaming, batch rename workflows, and CAD production cleanup. Function Syntax 🚀 Main command: RenameLayer 🪟 Dialog title: Layer Rename v3.5 📄 Temporary DCL file: RL_Temp.dcl in the AutoCAD roaming Support folder. SEO Optimized Overview 🧱 This AutoCAD layer rename tool helps users standardize drawing layer names without editing each layer manually in the Layer Properties Manager. 🔎 The routine reads the active drawing layer table, builds a sorted layer list, and allows the user to filter layer names before applying rename actions. 🧹 It supports common CAD cleanup operations such as adding prefixes, adding suffixes, removing unwanted text, replacing old strings, converting names to ALL CAPS, and merging layers when needed. 📌 The workflow is useful for Civil 3D drawings, AutoCAD template cleanup, imported DWG layer cleanup, client CAD standards migration, xref cleanup preparation, and production drafting standards. Dialog Workflow 🪟 The command creates a temporary DCL dialog named LayerRename. 🔍 The Search field filters visible layer names using wildcard matching around the typed text. 📋 The multi-select layer list lets the user choose individual layers for the rename operation. ✅ If no layer is selected, the tool processes all currently visible filtered layers. 🔁 The Apply button runs the current rename pass and keeps the dialog workflow active for additional cleanup passes. 🚪 The OK button applies the final settings and exits the dialog. Layer Rename Controls ➕ Prefix: adds text before each selected layer name. ➕ Suffix: adds text after each selected layer name. 🧹 Remove String: removes a defined string from each selected layer name. 🔄 Replace Old/New: replaces one layer name fragment with another layer name fragment. ✳️ Wildcard replacement: supports * patterns so fixed prefixes or suffixes can be changed while preserving the variable middle part of the layer name. 🔠 ALL CAPS: converts final renamed layers to uppercase for strict CAD standards. 🔀 Auto Merge: merges into an existing target layer when the generated destination layer already exists. Important AutoCAD Commands and API Calls 🧩 vla-get-layers reads the Layers collection from the active drawing. 🧩 wcmatch performs wildcard matching for layer filtering and pattern replacement. 🧩 vl-string-subst removes or replaces strings inside layer names. 🧩 _.RENAME _LA renames a layer when the new destination layer does not already exist. 🧩 _.LAYMRG merges the source layer into an existing destination layer when Auto Merge is enabled. 🧩 vla-startundomark and vla-endundomark group the rename operation into one undoable action. Internal Helper Functions 🧩 RL:SafeStr safely converts nil values and blank dialog values to usable strings. 🧩 RL:BuildList builds the filtered layer list, excluding layer 0 and xref-dependent layers containing |. 🧩 RL:IdxToNames converts selected DCL list indices back into real layer names. 🧩 RL:Replace performs direct replacement and wildcard-style layer name replacement. 🧩 RL:ExecuteRename applies remove, replace, prefix, suffix, ALL CAPS, rename, and Auto Merge logic. 🧩 RL:WriteDCL writes the temporary DCL interface used by the command. Functionalities ✅ Batch rename multiple AutoCAD layers from a DCL dialog. ✅ Search and filter layer names before applying changes. ✅ Rename selected layers or all currently filtered visible layers. ✅ Add layer name prefixes for office, discipline, phase, or project naming standards. ✅ Add layer name suffixes for status, revision, project phase, or workflow classification. ✅ Remove obsolete layer name fragments from imported or legacy drawings. ✅ Replace old layer standards with new naming conventions. ✅ Convert final layer names to uppercase for strict DWG standards. ✅ Merge matching layer names automatically when destination layers already exist. ✅ Keep xref-dependent layers protected by excluding names with the xref separator. Result ✅ The drawing layer table is renamed, cleaned, standardized, and easier to manage. ✅ Large layer cleanup tasks can be completed faster than manual layer-by-layer editing. ✅ CAD standards migration becomes easier for AutoCAD and Civil 3D production drawings. ✅ The Apply workflow allows iterative cleanup without restarting the command every time. Important Notes ⚠️ This tool changes layer names in the active drawing. ⚠️ Auto Merge uses LAYMRG, so objects from the source layer may be moved into an existing target layer. ⚠️ Review broad filters carefully before clicking Apply, especially on production drawings. ⚠️ Xref-dependent layers are intentionally skipped; edit them in the source xref drawing if required. 🧠 Recommended workflow: save the DWG, filter layer names, run a small controlled batch, review results, then continue with larger cleanup operations. Tags 🏷️ AutoCAD, 🏷️ AutoLISP, 🏷️ Civil 3D, 🏷️ Layer Management, 🏷️ Rename Layers, 🏷️ Layer Rename, 🏷️ DCL Dialog, 🏷️ Batch Rename, 🏷️ Layer Filter, 🏷️ LAYMRG, 🏷️ CAD Standards, 🏷️ CAD Automation