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.

Fast Layer Visibility Control in AutoCAD: Isolate, Hide & Invert Layers

Control layer visibility, turn on/off selected layers, and invert layer states in AutoCAD using FLA.lsp. Free AutoLISP script for fast drafting.
Fast Layer Control: Turn On, Off, and Invert Layers Instantly

Managing layer visibility in complex AutoCAD sheets can quickly turn into a time sink. Waiting for the Layer Properties Manager palette to open or repeatedly typing long commands like LAYISO, LAYOFF, and LAYON just to check underlying dimensions disrupts your drawing momentum.

The FLA.lsp (Fast Layer Control) script compresses all core layer visibility controls into a single dynamic command. With four built-in modes—including a backtick shortcut for All On and a instant layer Invert function—you can isolate or hide elements on the fly without navigating heavy menus.


Available Command Modes

  • All On ():** Type the backtick key (`` ``) to unhide all layers in your drawing in a single keystroke.

  • Select On (1): Pick objects on your screen to keep their layers visible while instantly hiding all other layers (fast isolation).

  • Select Off (2): Enter continuous selection mode to click objects and instantly hide their respective layers one by one.

  • Invert (3): Instantly flip the visibility state of every layer in your drawing (turning visible layers off and hidden layers back on).


Step-by-Step Instructions

  1. Load FLA.lsp into your AutoCAD session using the APPLOAD command.

  2. Type FLA in the command line and hit Enter.

  3. Choose your option from the prompt [All On() / Select On(1) / Select Off(2) / Invert(3)]`:

    • Press 1 and select target objects to isolate their layers.

    • Press 2 and click objects sequentially to turn off their layers. Press Enter when finished.

    • Press 3 to invert visible and hidden layers across your entire drawing.

    • Press ` (backtick) to restore all layers to visible state.


AutoLISP Code (FLA.lsp)

Copy the code below and save it as FLA.lsp inside your AutoCAD support folder:

(defun c:FLA ( / *error* cmdecho osmode acadobj doc layercol promptStr opt ss i ent layname layers )
  (vl-load-com)
  (setq acadobj (vlax-get-acad-object)
        doc (vla-get-activedocument acadobj)
        layercol (vla-get-layers doc))
  (vla-startundomark doc)
  (setq cmdecho (getvar "cmdecho")
        osmode (getvar "osmode"))
  (setvar "cmdecho" 0)
  (defun *error* (msg)
    (setvar "cmdecho" cmdecho)
    (setvar "osmode" osmode)
    (vla-endundomark doc)
    (princ "\nCAD Lisp [www.daolpro.com]")
    (princ)
  )
  (if (not *AA_last_opt*)
    (setq *AA_last_opt* "1")
  )
  (initget "` 1 2 3")
  (setq promptStr (strcat "\n[All On(`) / Select On(1) / Select Off(2) / Invert(3)] <" *AA_last_opt* ">: "))
  (setq opt (getkword promptStr))
  (if (not opt) 
    (setq opt *AA_last_opt*)
    (setq *AA_last_opt* opt)
  )
  (cond
    ((equal opt "`")
     (command "._-layer" "_on" "*" "")
     (princ "\nAll On")
    )
    ((equal opt "1")
     (princ "\nSelect On: ")
     (if (setq ss (ssget))
       (progn
         (setq layers '())
         (repeat (setq i (sslength ss))
           (setq ent (ssname ss (setq i (1- i)))
                 layname (cdr (assoc 8 (entget ent))))
           (if (not (member layname layers))
             (setq layers (cons layname layers))
           )
         )
         (command "._-layer" "_off" "*" "_y" "")
         (foreach l layers
           (vl-catch-all-apply 'vla-put-layeron (list (vla-item layercol l) :vlax-true))
         )
       )
     )
    )
    ((equal opt "2")
     (princ "\nSelect Off (Continuous): ")
     (while
       (progn
         (setvar "ERRNO" 0)
         (setq ent (entsel "\nSelect object to turn layer OFF (Enter to exit): "))
         (cond
           ((= (getvar "ERRNO") 52) nil)
           (ent
            (setq layname (cdr (assoc 8 (entget (car ent)))))
            (vl-catch-all-apply 'vla-put-layeron (list (vla-item layercol layname) :vlax-false))
            t
           )
           ((= (getvar "ERRNO") 7) t)
           (t nil)
         )
       )
     )
    )
    ((equal opt "3")
     (vlax-for lay layercol
       (if (= (vla-get-layeron lay) :vlax-true)
         (vla-put-layeron lay :vlax-false)
         (vla-put-layeron lay :vlax-true)
       )
     )
     (princ "\nInvert")
    )
  )
  (setvar "cmdecho" cmdecho)
  (setvar "osmode" osmode)
  (vla-endundomark doc)
  (princ "\nCAD Lisp [www.daolpro.com]")
  (princ)
)

Efficiency Tip

Use the Invert (Option 3) mode during complex drawing reviews to quickly cross-check hidden background layers or verify clean geometry without resetting your isolated workspace settings manually.

Post a Comment