What it does
Select Objects by Layer with the SELBYLAYER AutoLISP command
Builds an active-layout selection set from an exact layer name so the result can be inspected or passed to the next CAD command without mixing model and paper-space objects.
- AutoLISP command
- SELBYLAYER
- Difficulty
- Beginner
Applicable disciplines
CAD workflows that use this routine
Requirements and compatibility
What it needs
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 select-objects-by-layer.lsp AutoLISP code
;; CADLisp Tools - Select Objects by Layer
(defun c:SELBYLAYER (/ layer ss)
(setq layer (getstring T "\nExisting layer name: "))
(cond
((= layer "") (prompt "\nLayer name cannot be blank."))
((null (tblsearch "LAYER" layer)) (prompt "\nLayer not found."))
((setq ss (ssget "_X" (list (cons 8 layer) (cons 410 (getvar "CTAB")))))
(sssetfirst nil ss)
(prompt (strcat "\nSelected " (itoa (sslength ss))
" object(s) in the current layout.")))
(T (prompt "\nNo objects found on that layer in the current layout.")))
(princ))
Setup
How to install the select-objects-by-layer.lsp file
- 1Download and review the source code.
- 2Load the .lsp file with APPLOAD in a copy of a drawing.
- 3Keep the routine session-only until it has been tested for your CAD version and standards.
Command workflow
How to run the SELBYLAYER command
- 1Run SELBYLAYER.
- 2Enter an exact existing layer name.
- 3Continue with another command using the highlighted active-layout selection.
Worked example
Example: Select all objects on ANNO-TEXT in the active layout.
- Run SELBYLAYER.
- Enter ANNO-TEXT.
- Inspect the highlighted set.
Objects matching that layer in the current layout are selected.
Read before use
Notes and limitations
- Uses an exact case-insensitive layer-name match.
- Does not select matching objects from other layouts or nested block/xref content.
- Objects on locked layers can be selected but may not be editable.
- Not manually CAD-tested.
Version history