LayerCreation

Short description

  • LayerCreation — create/update a layer with True Color + Color Books support, plus a “Set as current layer” toggle (DCL with CLI fallback).
  • Fields: Name, Color (ACI / RGB / ColorBook), Linetype, Lineweight, Transparency; also sets defaults for NEW objects (CELTSCALE, CETRANSPARENCY, THICKNESS).
  • Runs a DCL dialog when the DCL core is healthy; otherwise runs NEWLAYERCLI (always works).
layercreation 000

Command:

  • LayerCreation
  • NEWLAYERCLI

Description:

  • LayerCreation is a layer creation/update tool that supports ACI colors, RGB truecolor, and Color Book colors through the AutoCAD color dialogs, and can optionally set the new layer as current.
  • When DCL is available, it generates a temporary dialog to capture layer properties and default settings; if the DCL core is not usable, it automatically falls back to a command-line workflow (NEWLAYERCLI).
  • The routine creates the layer if missing, sets Linetype, Lineweight, and Transparency via scripted -LAYER calls, then applies the selected color via the layer’s TrueColor object (supports book colors and RGB).
  • Finally, it applies drawing defaults for newly created objects (CELTSCALE, CETRANSPARENCY, THICKNESS) and optionally sets CLAYER to the created/updated layer based on the toggle.

Helper function: (if any)​

  • NL:_dclReadyP — checks whether core DCL functions exist as callable subrs, to decide between DCL dialog vs CLI fallback without using fboundp.
  • NL:_trim / NL:_illegalLayerNameP — trims input and validates layer names against forbidden characters and empty names.
  • NL:_getLinetypes / NL:_ensureLinetypeLoaded — enumerates available linetypes and loads missing ones from acad.lin when needed.
  • NL:_pickColor — opens the truecolor/color book dialog (acad_truecolordlg) with fallback to acad_colordlg; persists last selection.
  • NL:_parseColorText — parses manual color text input as ColorBook (BOOK$NAME), RGB (r,g,b), or ACI index, returning the selector list used for TrueColor application.
  • NL:_applyColorToLayer — applies ACI/RGB/ColorBook colors to a layer using its TrueColor object (supports SetRGB and SetColorBookColor).
  • NL:_makeOrUpdateLayer — creates the layer if missing and sets Linetype/Lineweight/Transparency using scripted -LAYER commands.
  • NL:_applyDefaultsAndMaybeSetCurrent — safely sets drawing defaults (CELTSCALE, CETRANSPARENCY, THICKNESS) and optionally sets the new layer current, using a protected setvar wrapper.
  • DCL temp helpers — generate unique temp DCL filenames, write dialog text, and ensure cleanup after closing.

Functionalities:

  • Dual interfaceLayerCreation uses DCL when available; otherwise it runs NEWLAYERCLI which prompts in the command line and always works.
  • Layer name validation — rejects empty names and names containing forbidden characters (\ / : ; * ? " < > | , =).
  • Color selection — supports three color modes: ACI index (62), RGB truecolor (420), and Color Book color (430), with persistent “last used” values.
  • Manual color input — dialog allows typing ACI, r,g,b, or BOOK$COLOR; parser converts it into the internal selector list used for TrueColor application.
  • Linetype management — linetypes are listed from the drawing; missing linetypes can be auto-loaded before assignment.
  • Layer creation/update — if the layer does not exist, creates it; then sets Linetype, Lineweight, and Transparency using -LAYER scripted calls; color is applied afterwards via TrueColor API to support RGB/books.
  • Defaults for new objects — applies CELTSCALE (default 0.05), CETRANSPARENCY (default 0), and THICKNESS (default 0) using a safe setvar wrapper so invalid settings do not cancel the command.
  • Set current toggle — both UI flows allow setting the created/updated layer as current (default Yes/checked).
  • Cleanup — DCL version writes a unique temp dialog file, loads/unloads it, then deletes it; color selection is persisted for the next run.

Result:

  • Running LayerCreation creates or updates a layer with the specified name, linetype, lineweight, transparency, and color (ACI/RGB/ColorBook), then applies the configured defaults for new objects and optionally sets the new layer current.
  • If the DCL core is not usable, the routine automatically falls back to NEWLAYERCLI, which collects the same key inputs via the command line and performs the same layer creation/update and default-setting steps.
  • The last used color selection is retained for subsequent runs, enabling consistent layer creation workflows across sessions.

Images, animations etc.

layercreation 000
layercreation 001
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="LayerCreation">
<src:RibbonToolTip.ExpandedContent>
<StackPanel>
<TextBlock Background="AntiqueWhite" TextAlignment="Left">
<Bold>Function Syntax: LayerCreation</Bold>
<LineBreak/>
<Bold>Version: 1 Date: 14.12.2025</Bold>
<LineBreak/>
<LineBreak/>
<Hyperlink>AI+</Hyperlink>
<LineBreak/>
<Bold><Run Foreground="DarkBlue">LayerCreation.LSP — Operational Summary</Run></Bold><LineBreak/>
<Run>This program creates or updates an AutoCAD layer and optionally sets it as the current layer, while also setting default variables for newly created objects.</Run><LineBreak/>
<Run Foreground="DarkRed">It does not require the user to select blocks or entities.</Run><LineBreak/>
<LineBreak/>

<Bold><Run Foreground="DarkBlue">How the User Runs It</Run></Bold><LineBreak/>
<Run>Available commands:</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">LayerCreation</Run><Run> — preferred entry point; uses a DCL dialog when DCL core functions are available.</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">NEWLAYERCLI</Run><Run> — command-line fallback that always works and supports the same key inputs.</Run><LineBreak/>
<LineBreak/>

<Bold><Run Foreground="DarkBlue">What the Program Does</Run></Bold><LineBreak/>
<Run>Core objective:</Run><LineBreak/>
<Run>• Create a new layer if it does not exist, or update it if it already exists.</Run><LineBreak/>
<Run>• Apply user-specified properties: </Run><Run Foreground="DarkRed">Color</Run><Run> (ACI or RGB or Color Book), </Run><Run Foreground="DarkRed">Linetype</Run><Run>, </Run><Run Foreground="DarkRed">Lineweight</Run><Run>, and </Run><Run Foreground="DarkRed">Transparency</Run><Run>.</Run><LineBreak/>
<Run>• Optionally set the created/updated layer as the </Run><Run Foreground="DarkRed">current layer</Run><Run>.</Run><LineBreak/>
<Run>• Set drawing defaults for new objects (system variables) such as linetype scale and thickness.</Run><LineBreak/>
<LineBreak/>

<Bold><Run Foreground="DarkBlue">User Inputs and Prompts</Run></Bold><LineBreak/>
<Run>LayerCreation (DCL dialog path):</Run><LineBreak/>
<Run>• Layer name (edit box).</Run><LineBreak/>
<Run>• Color entry as text (supports):</Run><LineBreak/>
<Run> • </Run><Run Foreground="DarkRed">ACI</Run><Run> like 7.</Run><LineBreak/>
<Run> • </Run><Run Foreground="DarkRed">RGB</Run><Run> like 255,255,255.</Run><LineBreak/>
<Run> • </Run><Run Foreground="DarkRed">Color Book</Run><Run> token like BOOK$COLORNAME (picked via dialog).</Run><LineBreak/>
<Run>• Color picker button </Run><Run Foreground="DarkRed">Pick...</Run><Run> to open the true color dialog (including color books when available).</Run><LineBreak/>
<Run>• Linetype selection (popup list).</Run><LineBreak/>
<Run>• Lineweight selection (popup list).</Run><LineBreak/>
<Run>• Transparency value in range </Run><Run Foreground="DarkRed">0 to 90</Run><Run>.</Run><LineBreak/>
<Run>• Toggle: </Run><Run Foreground="DarkRed">Set as current layer</Run><Run> (default checked).</Run><LineBreak/>
<Run>• Defaults for new objects:</Run><LineBreak/>
<Run> • </Run><Run Foreground="DarkRed">CELTSCALE</Run><Run> (default 0.05).</Run><LineBreak/>
<Run> • </Run><Run Foreground="DarkRed">THICKNESS</Run><Run> (default 0).</Run><LineBreak/>
<LineBreak/>
<Run>NEWLAYERCLI (command line path):</Run><LineBreak/>
<Run>• Prompts for layer name until valid.</Run><LineBreak/>
<Run>• Color prompt supports </Run><Run Foreground="DarkRed">Pick</Run><Run> (default) using true color dialog and color books when available.</Run><LineBreak/>
<Run>• Prompts for transparency, CELTSCALE, thickness, set-current Yes or No.</Run><LineBreak/>
<Run>• Prompts for linetype index and lineweight index from enumerated lists.</Run><LineBreak/>
<LineBreak/>

<Bold><Run Foreground="DarkBlue">Primary Functionalities (Bullet Summary)</Run></Bold><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">Validates layer names</Run><Run> and blocks illegal characters:</Run><LineBreak/>
<Run> • Disallows backslash, slash, colon, semicolon, asterisk, question mark, quotes, angle brackets, pipe, comma, equals.</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">Creates or updates</Run><Run> a layer using AutoCAD command calls:</Run><LineBreak/>
<Run> • Uses </Run><Run Foreground="DarkRed">-LAYER</Run><Run> to create the layer and set linetype, lineweight, and transparency.</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">Loads linetypes on demand</Run><Run> if a chosen linetype is not already in the drawing:</Run><LineBreak/>
<Run> • Uses </Run><Run Foreground="DarkRed">-LINETYPE</Run><Run> Load from acad.lin.</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">Applies color</Run><Run> using TrueColor so it can support:</Run><LineBreak/>
<Run> • Index colors (ACI).</Run><LineBreak/>
<Run> • TrueColor RGB.</Run><LineBreak/>
<Run> • Color book colors via SetColorBookColor.</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">Optionally sets the created layer current</Run><Run> by setting CLAYER.</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">Sets drawing defaults for new objects</Run><Run> using safe setvar calls that do not abort the routine if a variable is rejected:</Run><LineBreak/>
<Run> • CELTSCALE, CETRANSPARENCY, THICKNESS.</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">Provides a resilient UI strategy</Run><Run>:</Run><LineBreak/>
<Run> • Detects whether DCL core functions are healthy and automatically falls back to CLI if not.</Run><LineBreak/>
<Run> • Builds a temporary DCL file in TEMPPREFIX at runtime and deletes it after closing the dialog.</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">Persists last-used color</Run><Run> so the next run starts from the prior selection.</Run><LineBreak/>
<LineBreak/>

<Bold><Run Foreground="DarkBlue">Key Commands and Internal Helpers (Highlighted)</Run></Bold><LineBreak/>
<Run>Main commands:</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">C:LayerCreation</Run><Run> — runs dialog if DCL is available, otherwise routes to CLI.</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">C:NEWLAYERCLI</Run><Run> — always-available command-line workflow.</Run><LineBreak/>
<Run>Important AutoCAD command calls:</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">.-LAYER</Run><Run> — New, Ltype, LWeight, TRansparency actions.</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">.-LINETYPE</Run><Run> — Load linetype if missing.</Run><LineBreak/>
<Run>Important dialogs:</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">acad_truecolordlg</Run><Run> — preferred color picker (truecolor and color books).</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">acad_colordlg</Run><Run> — fallback color picker (ACI).</Run><LineBreak/>
<Run>Key helper routines:</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">NL:_illegalLayerNameP</Run><Run> — validates layer names.</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">NL:_getLinetypes</Run><Run> — enumerates linetypes from the drawing table.</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">NL:_applyColorToLayer</Run><Run> — applies ACI or RGB or color book via VLA TrueColor.</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">NL:_setvarSafe</Run><Run> — safe system-variable setter that traps errors.</Run><LineBreak/>
<LineBreak/>

<Bold><Run Foreground="DarkBlue">Outputs and Side Effects</Run></Bold><LineBreak/>
<Run>Creates or updates one layer in the current drawing session and changes properties immediately.</Run><LineBreak/>
<Run>Optionally sets CLAYER to the created or updated layer.</Run><LineBreak/>
<Run>Sets or attempts to set these variables for subsequent newly created objects:</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">CELTSCALE</Run><Run> default 0.05.</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">CETRANSPARENCY</Run><Run> default from chosen transparency (0-90).</Run><LineBreak/>
<Run>• </Run><Run Foreground="DarkRed">THICKNESS</Run><Run> default 0.</Run><LineBreak/>
<LineBreak/>

<Bold><Run Foreground="DarkBlue">Important Notes and Constraints</Run></Bold><LineBreak/>
<Run>• If DCL is not operational, the program automatically runs </Run><Run Foreground="DarkRed">NEWLAYERCLI</Run><Run> and continues without failure.</Run><LineBreak/>
<Run>• The dialog is generated dynamically to a temporary DCL file and removed after use.</Run><LineBreak/>
<Run>• Color text can be manually typed; the program parses ACI, RGB, or book tokens and applies the corresponding color method.</Run><LineBreak/>
<Run>• Transparency is clamped to a safe range (0-90) before being applied.</Run><LineBreak/>
<Run>• Linetype is ensured to be loaded before being assigned to the layer.</Run><LineBreak/>
<Run>• Uses COM via </Run><Run Foreground="DarkRed">vl-load-com</Run><Run> and VLA objects for TrueColor application.</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:

Share this page:

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Tags: 🏷️ Autocad Lisps, 🏷️ Layers, 🏷️ Layers_menu
0
Would love your thoughts, please comment.x
()
x