Short description
- DUPLICATELAYER / DUPLICATELAYERCURRENT — duplicate a layer’s properties into a new layer name via DCL, then set it current (optionally move the selected object).
- Copies common layer properties (Color, Linetype, Lineweight, Description) and PlotStyleName when available (STB-aware).
- DCL dialog asks for the new layer name and includes an “assign selected object” checkbox (used by DUPLICATELAYER).
Command:
- • DUPLICATELAYER
- • DUPLICATELAYERCURRENT
Description:
- DUPLICATELAYER: prompts the user to select an object, reads that object’s layer, then opens a dialog to enter a new layer name (default Copy_of_<layer>) and optionally assign the selected object to the new layer.
- If the target layer name does not already exist, creates it by copying properties from the source layer; if it exists, reuses it.
- Sets the new (or existing) layer as current (CLAYER), and if the checkbox is enabled, modifies the selected entity to the new layer and updates it.
- DUPLICATELAYERCURRENT: duplicates the current layer in the same way (default Copy_of_<current>) and sets the new layer current; the checkbox is displayed by the shared dialog but not used for reassignment in this command.
Helper function: (if any)
- • CreateLayerLike — creates a new layer and copies key properties from an existing layer: Color, Linetype, Lineweight, Description, and (when supported) PlotStyleName.
- • ShowRenameDialog — writes a temporary DCL file, shows a dialog to collect new layer name and an assign toggle, then returns (list name assignFlag) or NIL on cancel.
- • STB/CTB awareness — checks for PlotStyleName support and safely reads it (catch-all) before applying it to the new layer.
Functionalities:
- • Source layer detection — DUPLICATELAYER extracts source layer from the picked entity (DXF group 8); DUPLICATELAYERCURRENT uses CLAYER.
- • Dialog-driven naming — shows “Duplicate Layer” dialog with an edit box for the new name and a toggle defaulted to checked.
- • Existence check — uses tblsearch "LAYER" to determine whether the target name already exists before creating a new layer.
- • Layer creation by cloning — if missing, calls CreateLayerLike to create the new layer and copy properties from the source layer via VLA property gets/puts.
- • Set current layer — sets CLAYER to the new layer name in both commands.
- • Optional entity reassignment — for DUPLICATELAYER when the toggle is enabled, updates the entity’s layer (substitutes group 8), then calls entmod and entupd to apply changes.
- • Temporary DCL lifecycle — dialog definition is written to a temp file, loaded, used, unloaded, then the temp DCL file is deleted.
- • Validation / messaging — handles cancel/empty name/nothing selected conditions and prints status messages for created vs existing layers and assignment actions.
Result:
- After running DUPLICATELAYER, a new (or existing) layer name is selected via dialog; if it did not exist, it is created by copying properties from the picked object’s layer, then set as the current layer.
- If the dialog checkbox is enabled, the originally selected object is moved onto the new layer and updated; otherwise, only the current layer changes.
- After running DUPLICATELAYERCURRENT, the current layer is duplicated into the provided name (created if needed) and becomes the new current layer; no entity reassignment occurs.
Images, animations etc.
Log in to download.
Log in
Log in
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="DuplicateLayer">
<src:RibbonToolTip.ExpandedContent>
<StackPanel>
<TextBlock Background="AntiqueWhite" TextAlignment="Left">
<Bold>Function Syntax: DuplicateLayer</Bold>
<LineBreak/>
<Bold>Version: 4.1 Date:</Bold>
<LineBreak/>
<LineBreak/>
<Hyperlink>Function Syntax: AI+https://autolisps.blogspot.com/p/duplicatelayer.html </Hyperlink>
<LineBreak/>
<Bold>Command names</Bold><LineBreak/>
<Run>• DUPLICATELAYER (type </Run><Run Foreground="DarkRed">DUPLICATELAYER</Run><Run> at the AutoCAD command line)</Run><LineBreak/>
<Run>• DUPLICATELAYERCURRENT (type </Run><Run Foreground="DarkRed">DUPLICATELAYERCURRENT</Run><Run> at the AutoCAD command line)</Run><LineBreak/>
<LineBreak/>
<Bold>Description</Bold><LineBreak/>
<Run>This set of routines duplicates an existing layer by </Run><Run Foreground="DarkRed">creating a new layer</Run><Run> that inherits key properties from a source layer, prompts the user for the new name in a dialog, and then sets the new layer as the </Run><Run Foreground="DarkRed">current layer</Run><Run>. For DUPLICATELAYER, it can also </Run><Run Foreground="DarkRed">move the selected object</Run><Run> onto the new layer if a checkbox is enabled.</Run><LineBreak/>
<LineBreak/>
<Bold>Prerequisites</Bold><LineBreak/>
<Run>• Requires Visual LISP COM support via </Run><Run Foreground="DarkRed">(vl-load-com)</Run><Run>.</Run><LineBreak/>
<Run>• Requires permission to write a temporary DCL file for the rename dialog using </Run><Run Foreground="DarkRed">vl-filename-mktemp</Run><Run>.</Run><LineBreak/>
<LineBreak/>
<Bold>User interaction</Bold><LineBreak/>
<Run>• Both commands show a </Run><Run Foreground="DarkRed">DCL dialog</Run><Run> titled Duplicate Layer.</Run><LineBreak/>
<Run>• The dialog contains:</Run><LineBreak/>
<Run> • Edit box for the </Run><Run Foreground="DarkRed">New Layer Name</Run><Run>.</Run><LineBreak/>
<Run> • Toggle checkbox: </Run><Run Foreground="DarkRed">Assign selected object to new layer</Run><Run> (default checked).</Run><LineBreak/>
<Run> • OK and Cancel buttons.</Run><LineBreak/>
<LineBreak/>
<Bold>High-level workflow</Bold><LineBreak/>
<Run>• Creates a temporary DCL file each run, loads it, shows the dialog, then deletes the file.</Run><LineBreak/>
<Run>• Collects the new layer name and checkbox state from the dialog result.</Run><LineBreak/>
<Run>• Checks whether the target layer already exists via </Run><Run Foreground="DarkRed">tblsearch "LAYER"</Run><Run>.</Run><LineBreak/>
<Run>• If the layer does not exist, creates it by copying properties from the source layer using </Run><Run Foreground="DarkRed">CreateLayerLike</Run><Run>.</Run><LineBreak/>
<Run>• Sets the newly created or existing target layer as the current layer by setting </Run><Run Foreground="DarkRed">CLAYER</Run><Run>.</Run><LineBreak/>
<Run>• For DUPLICATELAYER only, optionally reassigns the selected entity to the new layer and updates it in the drawing.</Run><LineBreak/>
<LineBreak/>
<Bold>Functionalities</Bold><LineBreak/>
<Run>• Duplicates layer styling by copying properties from a source layer:</Run><LineBreak/>
<Run> • <Run Foreground="DarkRed">Color</Run>.</Run><LineBreak/>
<Run> • <Run Foreground="DarkRed">Linetype</Run>.</Run><LineBreak/>
<Run> • <Run Foreground="DarkRed">Lineweight</Run>.</Run><LineBreak/>
<Run> • <Run Foreground="DarkRed">Description</Run>.</Run><LineBreak/>
<Run> • <Run Foreground="DarkRed">PlotStyleName</Run> is copied only if it is available and readable, typically in STB-based drawings.</Run><LineBreak/>
<Run>• Prompts for a new layer name with a default suggestion based on the source layer.</Run><LineBreak/>
<Run>• Avoids duplicate creation by reusing an existing layer if the chosen name already exists.</Run><LineBreak/>
<Run>• Sets the duplicated layer as the </Run><Run Foreground="DarkRed">current layer</Run><Run> after creation or reuse.</Run><LineBreak/>
<Run>• Optionally assigns the originally selected object to the new layer (DUPLICATELAYER only).</Run><LineBreak/>
<LineBreak/>
<Bold>Command behavior details</Bold><LineBreak/>
<Run>• DUPLICATELAYER:</Run><LineBreak/>
<Run> • Prompts the user to select an entity.</Run><LineBreak/>
<Run> • Uses that entity layer as the source layer to duplicate.</Run><LineBreak/>
<Run> • Shows the dialog with default name </Run><Run Foreground="DarkRed">Copy_of_</Run><Run> plus the source layer name.</Run><LineBreak/>
<Run> • If the checkbox is enabled, moves the selected entity to the new layer using </Run><Run Foreground="DarkRed">entmod</Run><Run> and refreshes it using </Run><Run Foreground="DarkRed">entupd</Run><Run>.</Run><LineBreak/>
<Run>• DUPLICATELAYERCURRENT:</Run><LineBreak/>
<Run> • Uses the current layer from </Run><Run Foreground="DarkRed">CLAYER</Run><Run> as the source.</Run><LineBreak/>
<Run> • Shows the dialog with default name </Run><Run Foreground="DarkRed">Copy_of_</Run><Run> plus the current layer name.</Run><LineBreak/>
<Run> • Creates or reuses the layer, then sets it as current.</Run><LineBreak/>
<Run> • The checkbox is shown by the dialog, but the command does not use it and does not move any objects.</Run><LineBreak/>
<LineBreak/>
<Bold>Important commands and calls highlighted</Bold><LineBreak/>
<Run>• <Run Foreground="DarkRed">CreateLayerLike</Run> — creates a new layer and copies layer properties from the source layer using ActiveX.</Run><LineBreak/>
<Run>• <Run Foreground="DarkRed">ShowRenameDialog</Run> — writes a temporary DCL dialog, captures user input, deletes the DCL file.</Run><LineBreak/>
<Run>• <Run Foreground="DarkRed">entsel</Run> — selects the reference entity for DUPLICATELAYER.</Run><LineBreak/>
<Run>• <Run Foreground="DarkRed">entget</Run> and <Run Foreground="DarkRed">assoc 8</Run> — reads the selected entity layer name.</Run><LineBreak/>
<Run>• <Run Foreground="DarkRed">tblsearch "LAYER"</Run> — checks whether a layer already exists.</Run><LineBreak/>
<Run>• <Run Foreground="DarkRed">vla-Add</Run> and <Run Foreground="DarkRed">vla-Item</Run> — creates or retrieves layer objects in the Layers collection.</Run><LineBreak/>
<Run>• <Run Foreground="DarkRed">setvar "CLAYER"</Run> — sets the current layer.</Run><LineBreak/>
<Run>• <Run Foreground="DarkRed">entmod</Run> and <Run Foreground="DarkRed">entupd</Run> — updates the selected entity to the new layer and refreshes it.</Run><LineBreak/>
<LineBreak/>
<Bold>Outputs and messages</Bold><LineBreak/>
<Run>• If an entity is not selected (DUPLICATELAYER): prints </Run><Run Foreground="DarkRed">Nothing selected</Run><Run>.</Run><LineBreak/>
<Run>• If the dialog is cancelled: prints </Run><Run Foreground="DarkRed">Operation cancelled</Run><Run>.</Run><LineBreak/>
<Run>• If the layer is created: prints </Run><Run Foreground="DarkRed">Layer "name" created</Run><Run>.</Run><LineBreak/>
<Run>• If the layer already exists: prints </Run><Run Foreground="DarkRed">Layer "name" already exists, using it</Run><Run>.</Run><LineBreak/>
<Run>• If assignment is enabled and completed: prints </Run><Run Foreground="DarkRed">Selected object assigned to new layer</Run><Run>.</Run><LineBreak/>
<Run>• Always reports the new current layer name after success.</Run><LineBreak/>
<LineBreak/>
<Bold>Operational notes and limitations</Bold><LineBreak/>
<Run>• CreateLayerLike assumes the source layer exists; if the source layer name is invalid, the ActiveX call to </Run><Run Foreground="DarkRed">vla-Item</Run><Run> can error.</Run><LineBreak/>
<Run>• PlotStyleName is conditionally copied only when the property is available and readable; this is designed to avoid errors in CTB-based drawings or when PlotStyleName is not exposed.</Run><LineBreak/>
<Run>• The dialog always defaults the checkbox to enabled, but only DUPLICATELAYER actually applies it.</Run><LineBreak/>
<Run>• The code does not explicitly validate layer naming rules beyond non-empty text; names invalid for AutoCAD may fail at layer creation time.</Run><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:
Based on / Source code:
Open Website
Share this page:
Subscribe
Login
0 Comments
Oldest
