Function Syntax: DuplicateToSelectedLayer / DuplicateToSelectedLayer_Xref Version: 1.1 Date: 20.06.2026 6:38:53PM N/A Command name DuplicateToSelectedLayer (type DuplicateToSelectedLayer at the AutoCAD command line) Description This routine lets the user select one or more entities, choose a target layer from a dialog, then duplicates the entities onto that layer, applies draw order so the new copies are brought to front, and leaves the duplicated objects as the current selection for immediate follow-on operations. User interaction • The user is prompted to select entities to duplicate using any normal selection method. • A dialog titled Select Target Layer opens with a dropdown list of available layers. • The user clicks OK to run the duplication or Cancel to exit. High-level workflow • Reads the last used target layer from the environment variable DuplicateToLayer_LastLayer. • Builds a list of all drawing layers, excluding xref layers whose names match *|*. • Writes a temporary DCL file for the layer-selection dialog and loads it using load_dialog and new_dialog. • Populates the dropdown list with sorted layer names. • Sets the dropdown default selection to the last used layer when available. • On OK: • Stores the chosen layer back to DuplicateToLayer_LastLayer for next time. • Temporarily sets CLAYER to the chosen layer. • Runs the AutoCAD COPY command on the selection set with zero displacement (0,0 to 0,0), producing duplicates in place. • Retrieves the newly created entities via ssget "_P" (previous selection set). • Forces the copied entities to the chosen layer using CHPROP with the LA option. • Brings the copied entities to the front using DRAWORDER with Front. • Makes the copied entities the active selection using sssetfirst. • Restores the original current layer. Functionalities • Duplicates any selected entities in place (no movement) using COPY with zero displacement. • Lets the user choose the destination layer from a dialog dropdown. • Excludes xref layers from the destination list using the name pattern *|*. • Remembers the last chosen destination layer across sessions using getenv and setenv. • Moves the duplicated entities onto the chosen layer using CHPROP. • Changes draw order so duplicates are front-most. • Leaves the duplicated entities selected for immediate follow-up editing. Important commands and calls highlighted ssget — collects the initial entity selection set. vlax-for over Layers — enumerates layer names from the drawing. wcmatch "*|*" — filters out xref layers from the target layer list. getenv and setenv — persists the last used layer choice. load_dialog and new_dialog — loads the temporary DCL dialog. COPY — duplicates entities with zero displacement. ssget "_P" — retrieves the newly copied entities as the previous selection set. CHPROP with LA — assigns the new copies to the target layer. DRAWORDER Front — brings duplicates to the front. sssetfirst — makes the duplicated entities the active selection. setvar "CLAYER" — temporarily switches and then restores the current layer. Outputs and messages • If nothing is selected initially: prints No objects selected. • If the dialog cannot load: prints Unable to load dialog. • If cancelled in the dialog: prints Operation cancelled. • On success: prints the number of duplicated entities and confirms the target layer name, and indicates that the duplicates were brought to front. Operational notes and limitations • The routine uses AutoCAD commands (COPY, CHPROP, DRAWORDER) rather than entmakex, so it depends on command availability and user command settings. • COPY is executed with base point 0,0 and displacement 0,0, so duplicates are created directly on top of the originals. • The copied entities are identified using ssget "_P"; if another command changes the previous selection unexpectedly, the captured set may differ. • Xref layers are excluded only by name pattern; non-xref layers containing a pipe character could also be excluded. Description 📋 DuplicateToSelectedLayer is an AutoCAD and Civil 3D AutoLISP utility for copying selected entities to a chosen existing local layer. 🧩 It uses a temporary DCL layer picker, ignores xref-prefixed layers, remembers the last selected target layer, and brings the copied objects to the front. Function Syntax 🚀 Main command: DuplicateToSelectedLayer 📋 Select entities first inside the command, choose the destination layer from the DCL list, then the routine creates same-position duplicates. 🧠 The last chosen target layer is persisted with the DuplicateToLayer_LastLayer environment variable. SEO Optimized Overview 📋 DuplicateToSelectedLayer is an SEO-friendly AutoCAD layer copy tool for duplicating existing drawing objects onto another layer without moving their geometry. 🧱 The routine collects a selection set with ssget, shows only non-xref layers in a sorted DCL popup list, and then copies the selected entities using zero displacement. 🎯 After the copy operation, the new entities are moved to the chosen layer with CHPROP, sent to the front using DRAWORDER, and left selected for immediate review. 📌 This is useful for Civil 3D production drawings, CAD layer cleanup, visual alternatives, temporary design copies, layer standardization, and controlled duplication workflows. Primary Workflow 1️⃣ Load the AutoLISP file in AutoCAD or Civil 3D with APPLOAD or your menu loader. 2️⃣ Run the command shown above from the AutoCAD command line. 3️⃣ Follow the dialog, selection prompts, or file prompts used by DuplicateToSelectedLayer. 4️⃣ Review the command-line report and drawing result before continuing production work. Functionalities ✅ Duplicate one or many selected objects without changing their insertion position or geometry. ✅ Choose the target layer from a compact DCL list of local drawing layers. ✅ Exclude xref layers so copies are assigned only to editable local layers. ✅ Preserve the user's current layer by restoring CLAYER after the operation. ✅ Bring the duplicated entities to the front for immediate visibility. ✅ Select the duplicated entities at the end for direct editing, verification, or undo workflow. Important Functions and AutoCAD API 🧩 Temporary DCL generation creates the Select Target Layer dialog at runtime and deletes the DCL file after use. 🧩 The layer enumeration loop reads the AutoCAD Layers collection and filters out names containing the xref separator |. 🧩 getenv and setenv remember the previous target layer across command runs. 🧩 ssget, COPY, CHPROP, DRAWORDER, and sssetfirst are combined into one repeatable production workflow. Result 🎯 The result is a clean same-position duplicate set on the selected layer, useful for AutoCAD layer management and drawing production. 🟢 The command reports how many entities were duplicated and names the destination layer. Operational Notes and Limitations ⚠️ The routine changes the drawing by creating new entities and changing their layer assignment. ⚠️ The destination layer must already exist because the DCL lists existing local layers only. 🧠 Xref layers are intentionally hidden from the target list to avoid assigning copies to external-reference layer names. Tags 🏷️ AutoCAD, 🏷️ AutoLISP, 🏷️ Civil 3D, 🏷️ Layer Management, 🏷️ Duplicate Objects, 🏷️ DCL Dialog, 🏷️ CAD Automation, 🏷️ Drawing Cleanup