CAD Forum - tips, tricks, discussion and utilities for AutoCAD, Inventor, Revit and other Autodesk products [www.cadforum.cz]
CZ | EN | DE
Login or
registration
  Visitors: 6886

CAD tip CAD tip # 13822:

   
Question CAD 
 %  platform  category 
Q - question

Fast layer visibility toggle ON/OFF.

A - answer If you need to quickly toggle visibility of a specific layer or group of layers in AutoCAD or AutoCAD LT, you can add the appropriate command or function to AutoCAD. Then you can invoke it by typing the command name, by clicking on a specific tool in the tool palette, or assign it to a keyboard shortcut (hotkey).

Store the following LISP code in the LFT.LSP file and use the briefcase icon in the APPLOAD command to load it into each AutoCAD (or LT) session. Customize the name of the switched layer or layer mask.

;Layer thaw/freeze (for palette)

(vl-load-com)

(setq *acaddoc* (vla-get-activedocument (vlax-get-acad-object)))

(defun LFT (LFT_name / flg lo)
 (cond
      ( (= (strcase (getvar 'CLayer)) (strcase LFT_name))
        (princ "\nCannot freeze current layer")
      )
      ( (setq lo (tblobjname "LAYER" LFT_name))
	(setq lo (vlax-ename->vla-object lo))
        (vlax-put lo 'Freeze (setq flg (~ (vlax-get lo 'Freeze))))
        (if (= flg 0) (vla-regen *acaddoc* acActiveViewport))
      )
      ( (princ (strcat "\nLayer " LFT_name " does not exist.")))
 )
 (princ)

(defun C:LFT ( / LFT_name flg lo)
 (setq LFT_name "MYOWNLAYER") ; layer to process
 (cond
      ( (= (strcase (getvar 'CLayer)) (strcase LFT_name))
        (princ "\nCannot freeze current layer")
      )
      ( (setq lo (tblobjname "LAYER" LFT_name))
        (setq lo (vlax-ename->vla-object lo))
        (vlax-put lo 'Freeze (setq flg (~ (vlax-get lo 'Freeze))))
        (if (= flg 0) (vla-regen *acaddoc* acActiveViewport))
      )
      ( (princ (strcat "\nLayer " LFT_name " does not exist.")))
 )
 (princ)
)

(setq *LFTM_status* nil)

(defun C:LFTM ( / LFT_name)
 (setq LFT_name "MYOWNLAYERS*") ; layers to process (mask)
 (command "_-LAYER" (if *LFTM_status* "_FR" "_TH") LFT_name "")
 (setq *LFTM_status* (not *LFTM_status*))
 (princ)
)

(princ "\nLFT and LFTM toggle loaded.")
(princ)
)

Then you can use (via keyboard or hotkey, see CUI) the commands LFT and LFTM (multiple, wildcard mask), or assign/add an icon for a specific layer into your custom Tool palette. See Tip 13504. Repeated mouse-clicks on this icon will then toggle the selected layer on and off.

Enter this (including parentheses) as the Command string for the respective layer-icon:

(LFT "MYLAYERNAME")

ACADADTPlantACADMCivilMapACLT2024
100% *  CAD 
15.8.2023    66347×  

See also:
Tip 13878:SelectSimilar - extended selections for AutoCAD, incl. LT and Web versions
Tip 13288:LayoutLF - automatic switching of group layer filters.
Tip 13014:StickLay - unchangable, fixed layers for selected DWG objects.
Tip 12034:SolSimilar - select geometrically similar 3D solids.
Tip 8151:Keyboard shortcuts in AutoCAD for Mac.


Back   All CAD Tips



Have we helped you? If you want to support the CAD Forum web service, consider buying one of our CAD applications, or our custom software development offerings, or donating via PayPal (see above). You may also add a link to your web - like this "fan" link: CAD Forum - tips, utilities, blocks for Autodesk products
CAD:    OS:    Categ: 
Text:  FAQ glossary   



Featuring:
Add .CIT raster format support to AutoCAD and Map and Civil 3D
CITin More info


Please use these tips at your own risk.
Arkance Systems is not responsible for possible problems that may occur as a result of using any of these tips.
TOPlist