Short description
- LayersName2Clipboard — collect unique layer names from a user selection and copy them to the Windows clipboard as a newline-separated list
- Uses an HTMLFile COM object to access clipboardData and write text directly to the clipboard

Command:
- • LayersName2Clipboard
Description:
- Prompts the user to select entities, then scans the selection set and extracts each entity’s layer name (DXF group 8).
- Builds a list of unique layer names (no duplicates) in the order encountered, prints them to the command line, and concatenates them into a newline-separated string.
- Copies the resulting string (layers only) into the Windows clipboard so it can be pasted into other applications.
Helper function: (if any)
- • ClipPut — writes a text string to the Windows clipboard via an htmlfile COM object using parentWindow.clipboardData.setData.
- • DXF 8 — layer name group code used to extract an entity’s layer from entget data.
Functionalities:
- • User selection — uses ssget to collect entities; exits with a message if nothing is selected.
- • Layer extraction — iterates the selection set, calls entget, and reads (assoc 8) to obtain each entity’s layer name.
- • Deduplication — adds layer names to an in-memory list only if they are not already present (member check).
- • Reporting — prints “Unique layers in selection” and lists each layer name in the command line output.
- • Clipboard formatting — builds a single string containing only layer names separated by newline characters (one layer per line).
- • Clipboard write — calls ClipPut to copy the newline-separated list into the clipboard and prints confirmation.
- • COM cleanup — releases the temporary htmlfile object after writing to the clipboard.
Result:
- The command outputs the unique layer names used by the selected entities and copies those names to the clipboard as a clean, newline-separated list suitable for pasting elsewhere.
- If no objects are selected or no layer names are found, nothing is copied and an informational message is printed.
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="LayersNameToClipboard"> <src:RibbonToolTip.ExpandedContent> <StackPanel> <TextBlock Background="AntiqueWhite" TextAlignment="Left"> <Bold>Function Syntax: LayersNameToClipboard</Bold> <LineBreak/> <Hyperlink>web</Hyperlink> <LineBreak/> <Bold>Command name</Bold><LineBreak/> <Run>LayersNameToClipboard (type </Run><Run Foreground="DarkRed">LayersNameToClipboard</Run><Run> at the AutoCAD command line)</Run><LineBreak/> <LineBreak/> <Bold>Description</Bold><LineBreak/> <Run>This routine collects the </Run><Run Foreground="DarkRed">unique layer names</Run><Run> of the objects in a user selection set, strips simple MText-style formatting codes from the layer strings, and copies the resulting list to the </Run><Run Foreground="DarkRed">Windows clipboard</Run><Run> as plain text (one layer name per line).</Run><LineBreak/> <LineBreak/> <Bold>Prerequisite</Bold><LineBreak/> <Run>• Requires Visual LISP COM support via </Run><Run Foreground="DarkRed">(vl-load-com)</Run><Run>.</Run><LineBreak/> <LineBreak/> <Bold>User interaction</Bold><LineBreak/> <Run>• The user is prompted to create a selection set using </Run><Run Foreground="DarkRed">(ssget)</Run><Run>.</Run><LineBreak/> <Run>• If the user cancels or selects nothing, the routine prints </Run><Run Foreground="DarkRed">Nothing selected</Run><Run>.</Run><LineBreak/> <LineBreak/> <Bold>High-level workflow</Bold><LineBreak/> <Run>• Builds a selection set using </Run><Run Foreground="DarkRed">ssget</Run><Run>.</Run><LineBreak/> <Run>• Iterates through each entity in the selection set using </Run><Run Foreground="DarkRed">sslength</Run><Run> and </Run><Run Foreground="DarkRed">ssname</Run><Run>.</Run><LineBreak/> <Run>• Converts each entity name to a VLA object using </Run><Run Foreground="DarkRed">vlax-ename->vla-object</Run><Run>.</Run><LineBreak/> <Run>• Verifies the object exposes a Layer property using </Run><Run Foreground="DarkRed">vlax-property-available-p</Run><Run>.</Run><LineBreak/> <Run>• Reads the layer name using </Run><Run Foreground="DarkRed">vla-get-layer</Run><Run> and cleans it via </Run><Run Foreground="DarkRed">StripSimpleCodes</Run><Run>.</Run><LineBreak/> <Run>• Maintains a list of unique layer names by checking membership before adding.</Run><LineBreak/> <Run>• Converts the unique list to a newline-separated string.</Run><LineBreak/> <Run>• Copies the result to the Windows clipboard through an </Run><Run Foreground="DarkRed">htmlfile COM object</Run><Run> and ClipboardData SetData call.</Run><LineBreak/> <Run>• Prints a summary showing the number of unique layers copied and echoes the copied content.</Run><LineBreak/> <LineBreak/> <Bold>Functionalities</Bold><LineBreak/> <Run>• Extracts layer names from a user selection set.</Run><LineBreak/> <Run>• Ensures the output contains only </Run><Run Foreground="DarkRed">unique</Run><Run> layer names (no duplicates).</Run><LineBreak/> <Run>• Removes simple formatting sequences embedded in the layer string using </Run><Run Foreground="DarkRed">StripSimpleCodes</Run><Run>.</Run><LineBreak/> <Run>• Outputs the layer list as </Run><Run Foreground="DarkRed">plain text</Run><Run>, one entry per line.</Run><LineBreak/> <Run>• Copies the final list directly to the </Run><Run Foreground="DarkRed">clipboard</Run><Run> for immediate paste into other applications.</Run><LineBreak/> <LineBreak/> <Bold>Helper function behavior</Bold><LineBreak/> <Run>• <Run Foreground="DarkRed">StripSimpleCodes</Run> removes sequences that start with a backslash and typically end at the next semicolon.</Run><LineBreak/> <Run>• Intended to remove full formatting tokens such as \A1; \C256; \fArial; so only the readable layer name remains.</Run><LineBreak/> <LineBreak/> <Bold>Important commands and calls highlighted</Bold><LineBreak/> <Run>• <Run Foreground="DarkRed">(ssget)</Run> — prompts the user to select objects.</Run><LineBreak/> <Run>• <Run Foreground="DarkRed">sslength</Run> and <Run Foreground="DarkRed">ssname</Run> — iterates through the selection set.</Run><LineBreak/> <Run>• <Run Foreground="DarkRed">vlax-ename->vla-object</Run> — converts entity names to ActiveX objects.</Run><LineBreak/> <Run>• <Run Foreground="DarkRed">vlax-property-available-p</Run> — verifies the Layer property exists on the object.</Run><LineBreak/> <Run>• <Run Foreground="DarkRed">vla-get-layer</Run> — reads the layer name.</Run><LineBreak/> <Run>• <Run Foreground="DarkRed">vlax-create-object "htmlfile"</Run> — creates a COM object to access ClipboardData.</Run><LineBreak/> <Run>• <Run Foreground="DarkRed">ClipboardData SetData</Run> — writes the newline-separated text to the clipboard.</Run><LineBreak/> <LineBreak/> <Bold>Outputs and messages</Bold><LineBreak/> <Run>• If layers are found: prints </Run><Run Foreground="DarkRed">Copied N unique layer name(s) to clipboard</Run><Run> and lists the names.</Run><LineBreak/> <Run>• If the selection contains no valid Layer properties or nothing usable: prints </Run><Run Foreground="DarkRed">No valid layers found</Run><Run>.</Run><LineBreak/> <Run>• If nothing is selected: prints </Run><Run Foreground="DarkRed">Nothing selected</Run><Run>.</Run><LineBreak/> <LineBreak/> <Bold>Operational notes and limitations</Bold><LineBreak/> <Run>• Clipboard support relies on Windows COM interfaces; behavior may differ in non-Windows environments.</Run><LineBreak/> <Run>• The uniqueness check is case-sensitive because it uses </Run><Run Foreground="DarkRed">member</Run><Run> on strings; layers that differ only by case may appear separately.</Run><LineBreak/> <Run>• The formatting stripper removes backslash-initiated segments up to the next semicolon; unusual strings without semicolons are handled by removing a short portion after the backslash.</Run><LineBreak/> </TextBlock> <!-- Use MediaElement for GIF (static first frame) and Image as fallback --> </StackPanel> </src:RibbonToolTip.ExpandedContent> </src:RibbonToolTip> </ResourceDictionary>
Additional info:
Based on / Source code:
Open Website
Share this page:
Subscribe
Login
0 Comments
Oldest
