CADLisp Tools

Layers

Assign Selection to Existing Layer AutoLISP routine

Move selected objects onto an existing layer with validation and no layer creation. Download the .LSP source below and run the TOLAYER command after loading it.

⌘ TOLAYERv1.0.0BeginnerUpdated Sep 12, 2026

What it does

Assign Selection to Existing Layer with the TOLAYER AutoLISP command

A conservative layer-assignment helper. It checks that the target layer already exists, then updates only the selected entities.

AutoLISP command
TOLAYER
Difficulty
Beginner

Applicable disciplines

CAD workflows that use this routine

Requirements and compatibility

What it needs

AutoLISP

Software rows marked “Not tested” are not compatibility claims. Test the routine in a copy of your drawing and CAD version.

Downloadable source code

Review the assign-layer.lsp AutoLISP code

assign-layer.lspAUTOLISP
;; CADLisp Tools - Assign Selection to Existing Layer
(defun ct-tl:layer-state (name / row flags color)
  (if (setq row (tblsearch "LAYER" name))
    (progn
      (setq flags (cdr (assoc 70 row)) color (cdr (assoc 62 row)))
      (cond
        ((/= 0 (logand flags 16)) "xref-dependent")
        ((/= 0 (logand flags 4)) "locked")
        ((/= 0 (logand flags 1)) "frozen")
        ((< color 0) "off")
        (T "usable")))))

(defun ct-tl:editable-p (data / row flags)
  (and data
       (setq row (tblsearch "LAYER" (cdr (assoc 8 data))))
       (setq flags (cdr (assoc 70 row)))
       (= 0 (logand flags 20))))

(defun c:TOLAYER (/ *error* changed data entity index layer set skipped state undo-started)
  (defun *error* (message)
    (if undo-started (command-s "_.UNDO" "_End"))
    (if (and message (not (wcmatch (strcase message) "*CANCEL*,*QUIT*,*EXIT*")))
      (prompt (strcat "\nTOLAYER error: " message)))
    (princ))
  (setq layer (getstring T "\nExisting target layer: ")
        state (ct-tl:layer-state layer))
  (cond
    ((null state) (prompt "\nLayer not found; no objects changed."))
    ((/= state "usable")
      (prompt (strcat "\nTarget layer is " state "; no objects changed.")))
    (T
      (prompt "\nSelect objects to move: ")
      (if (setq set (ssget))
        (progn
          (setq index 0 changed 0 skipped 0)
          (if (= 0 (logand 8 (getvar "UNDOCTL")))
            (progn (command "_.UNDO" "_Begin") (setq undo-started T)))
          (repeat (sslength set)
            (setq entity (ssname set index) data (and entity (entget entity)))
            (if (and (ct-tl:editable-p data) (assoc 8 data)
                     (entmod (subst (cons 8 layer) (assoc 8 data) data)))
              (progn (entupd entity) (setq changed (1+ changed)))
              (setq skipped (1+ skipped)))
            (setq index (1+ index)))
          (if undo-started (progn (command "_.UNDO" "_End") (setq undo-started nil)))
          (prompt (strcat "\nMoved " (itoa changed) " object(s); skipped " (itoa skipped) ".")))
        (prompt "\nNo objects selected."))))
  (princ))

Setup

How to install the assign-layer.lsp file

  1. 1Review the routine with your CAD standards owner.
  2. 2Load the file with APPLOAD.
  3. 3Confirm the destination layer is unlocked before use.

Command workflow

How to run the TOLAYER command

  1. 1Run TOLAYER.
  2. 2Type the exact name of an existing target layer.
  3. 3Select the objects to move and press Enter.

Worked example

Example: Move selected annotation objects to a standard annotation layer.

  1. Confirm the destination layer exists.
  2. Run TOLAYER and enter that layer name.
  3. Select only the intended annotations.
Expected result

The selected objects now reference the requested layer.

Read before use

Notes and limitations

  • Does not create missing layers.
  • Locked-layer and referenced-object restrictions still apply.
  • Does not change object overrides.

Version history

Changelog

v1.0.0Sep 12, 2026Initial starter implementation.

Keep automating

Related tools

Standards & QA6 disciplines

Drawing Layer Checker

Report objects on Layer 0 or Defpoints and list locked, frozen, or off layers.

⌘ LAYERCHECKIntermediateCAD support: not tested
Updated Sep 18, 2026VIEW TOOL →
Selection & Editing6 disciplines

Select Objects by Layer

Select objects on an existing named layer in the active model or paper-space layout.

⌘ SELBYLAYERBeginnerCAD support: not tested
Updated Sep 18, 2026VIEW TOOL →