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 Control: Turn On, Off, and Invert Layers Instantly

Free AutoCAD LISP to instantly turn layers on, off, or invert visibility without the Layer Manager.

 [AutoCAD LISP] Fast Layer Control: Turn On, Off, and Invert Layers Instantly (FLA.lsp)

Fast Layer Control: Turn On, Off, and Invert Layers Instantly
Managing layers in AutoCAD can often feel like a tedious chore. When working on complex drawings with dozens of layers, opening the heavy Layer Properties Manager or constantly typing default commands just to isolate or hide a few elements drastically slows down your momentum. Without an optimized tool, you waste valuable seconds clicking through menus, hunting for specific layer names, and losing your design focus.

This is where the FLA (Fast Layer Control) LISP comes in. It provides an instantaneous, command-line-driven way to control your layer visibility without ever breaking your workflow.

Why You Should Use the 'FLA' LISP

  • Eliminate Layer Manager Lag: No more waiting for the heavy Layer Properties window to load just to toggle a few lines.
  • Instant Isolation & Hiding: Quickly turn on only the layers you select, or instantly hide the objects cluttering your screen with a simple click.
  • Seamless Inversion: Switch back and forth between hidden and visible data using the invert function, making auditing complex drawings incredibly easy.
  • Boosted Drafting Speed: By keeping your hands on the keyboard and mouse shortcuts, you can shave off hours of repetitive work over a large project.

How It Works (Step-by-Step Guide)

  1. Load the LISP: Load the FLA.lsp file into your AutoCAD session using the APPLOAD command.
  2. Run the Command: Type FLA in the command line and press Enter.
  3. Choose Your Option: The command line will prompt you with four intuitive options: [All On(`) / Select On(1) / Select Off(2) / Invert(3)]`.
  4. All On (`): Enter the backtick key () to instantly turn all layers in the drawing back on.
  5. Select On (1): Enter 1, then select objects on your screen. All other layers will turn off, leaving only the layers of the selected objects visible.
  6. Select Off (2): Enter 2, then select objects to immediately turn off their corresponding layers.
  7. Invert (3): Enter 3 to instantly flip the visibility status of all layers (visible layers become hidden, and hidden layers become visible).

Wrapping Up

The FLA LISP is a lightweight yet essential tool for anyone looking to maximize their AutoCAD efficiency. By turning complex layer management into a few simple keystrokes, it keeps your workspace clean and your focus sharp. Give it a try, add it to your Startup Suite, and experience a much faster drafting process!

The LISP Code

(defun c:FLA ( / cmdecho promptStr opt ss i ent layname layers currlyr acadobj doc layercol )
  (vl-load-com)
  (setq cmdecho (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  
  (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)
  )
  
  (setq acadobj (vlax-get-acad-object)
        doc (vla-get-activedocument acadobj)
        layercol (vla-get-layers doc))
  
  (cond
    ((equal opt "`")
     (command "._-layer" "_on" "*" "")
     (princ "\nAll On")
    )
    
    ((equal opt "1")
     (princ "\nSelect On: ")
     (if (setq ss (ssget))
       (progn
         (setq layers '()
               currlyr (getvar "clayer"))
         (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: ")
     (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))
          )
         )
         (foreach l layers
           (vl-catch-all-apply 'vla-put-layeron (list (vla-item layercol l) :vlax-false))
         )
       )
     )
    )
    
    ((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)
  (princ)
)

Post a Comment