CADLISPMASTER
Stop wasting time on repetitive AutoCAD tasks. CAD LISP Master provides free, efficient AutoLISP codes and clear tutorials designed to automate your workflow and speed up your drafting.

Create Multiple Layers and Assign Colors Instantly

Free AutoCAD LISP for bulk layer creation. Automatically create setup layers and match ACI colors easily.

 [AutoCAD LISP] Create Multiple Layers and Assign Colors Instantly (CLA.lsp)

Create Multiple Layers and Assign Colors Instantly
Have you ever found yourself manually creating dozen of layers in AutoCAD, typing names one by one, and painstakingly assigning color numbers? It is an absolute productivity killer. If you regularly work with structured drawings that require standardized numerical layers, doing this manually is not just tedious—it’s a waste of your valuable engineering time.

This is where the CLA (Create Layers Automatically) LISP comes in. It completely automates the layer creation process, letting you generate a single layer or a massive range of layers (from 1 to 255) with their corresponding index colors in just a single second.

Why You Should Use the 'CLA' LISP

  • Eliminate Repetitive Tasks: No more clicking "New Layer" dozens of times and changing colors manually.
  • Mass Layer Creation: Instantly generate a sequence of layers (e.g., 1 to 50) with a single command.
  • Auto-Color Matching: The LISP automatically maps the layer name to its corresponding AutoCAD Index Color (ACI) number, ensuring perfect drawing standards.
  • Flawless Input Handling: It intelligently recognizes both hyphens (-) and tildes (~) for ranges, making it incredibly user-friendly.

How It Works (Step-by-Step Guide)

  1. Load the LISP File: Load the CLA.lsp file into your AutoCAD using the APPLOAD command.
  2. Run the Command: Type CLA in the command line and press Enter.
  3. Input the Layer Range: The prompt will ask you to enter a layer number or range.
  • Single Layer: Enter a single number (e.g., 5).
  • Range: Enter a range using a hyphen or tilde (e.g., 1-10 or 1~10).
  1. Instant Execution: The LISP will automatically create the layers, set their names to the numbers, match the color to that specific number, and display a [Success] message in the command line.

Wrapping Up

The CLA LISP is a must-have tool for CAD managers, structural detailers, and anyone who wants to skip the mundane setup phase of drafting. By automating standard layer generation, you can keep your focus entirely on designing and detailing.

If you found this helpful, feel free to share it with your fellow CAD colleagues!

The LISP Code

(defun c:CLA ( / cmde inp pos start end i)
  (setq cmde (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (setq inp (getstring "\nEnter layer number or range (e.g., 3 or 1-10): "))
  (cond
    ((vl-string-search "-" inp)
     (setq pos (vl-string-search "-" inp))
     (setq start (atoi (substr inp 1 pos)))
     (setq end (atoi (substr inp (+ pos 2)))))
    ((vl-string-search "~" inp)
     (setq pos (vl-string-search "~" inp))
     (setq start (atoi (substr inp 1 pos)))
     (setq end (atoi (substr inp (+ pos 2)))))
    (t
     (setq start (atoi inp))
     (setq end start))
  )
  (if (and (> start 0) (<= start 255) (> end 0) (<= end 255) (<= start end))
    (progn
      (setq i start)
      (while (<= i end)
        (command "._-layer" "_n" (itoa i) "_c" i (itoa i) "")
        (setq i (1+ i))
      )
      (princ (strcat "\n[Success] Created layers from " (itoa start) " to " (itoa end) "."))
    )
    (princ "\n[Error] Invalid input. Please enter a valid number or range (1-255).")
  )
  (setvar "CMDECHO" cmde)
  (princ)
)

Post a Comment