Message 1 of 2
Lisp Command to freeze layers in Viewport
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I created a Lisp that freezes all of my viewport layers, with the exception of a selected few layers. The Lisp works, except for freezing my Xref background as well. Do you have any suggestions on how to get it to always ignore the background?
I have also tried to lock the layers, and it ignored the lock.
;Select VP and does a VP Freeze on all layers except for what is listed in the Laylist
(defun c:QW (/ sset num vprt laylist allLayers xrefLayers layerName blockName)
(setvar "CMDECHO" 0)
;; List of layers to remain visible (no VP Freeze)
(setq laylist '(
"0"
"AE-GENERAL"
"AE-BACKGROUND"
"AE-BACKGROUND-DOORS"
"AE-BACKGROUND-RM_TAGS"
"AE-LOUDSPEAKER-LAY-IN-INTERCOM"
"AE-LOUDSPEAKER-GYP-INTERCOM"
"AE-LOUDSPEAKER HORN-OUTSIDE-INTERCOM"
"AE-LOUDSPEAKER HORN-INSIDE-INTERCOM"
"AE-LOUDSPEAKER DISMISSAL-INTERCOM"
"AE-CONTROL-INTERCOM"
"AE-LOUDSPEAKER-WALL-INTERCOM"
"AE-LOUDSPEAKER-PENDANT"
"AE-CBL-70V SPKR"
"AE-AMPLIFIER-INTERCOM"
"AE-TELECOM CLOSET"
"AE-TELECOM CLOSET EQUIPMENT"
))
;; Initialize a list to store Xref layers
(setq xrefLayers '())
;; Retrieve all block references in the drawing
(setq blocks (ssget "_X" '((0 . "INSERT") (66 . 1)))) ; Get only block references
;; Loop through all block references to detect Xrefs
(if blocks
(repeat (sslength blocks)
(setq blockName (cdr (assoc 2 (entget (ssname blocks 0))))) ; Get block name
(if (wcmatch blockName "*|*") ; Check if block is an Xref (contains "|")
(progn
;; Collect the layer name of the Xref block reference
(setq xrefLayer (cdr (assoc 8 (entget (ssname blocks 0)))))
(if (not (member xrefLayer xrefLayers))
(setq xrefLayers (cons xrefLayer xrefLayers))) ; Add to xrefLayers list
)
)
)
)
;; Ensure we're in Paper Space before proceeding
(if (> (getvar "cvport") 1) (command "pspace"))
(princ "\nSelect one or more viewports: ")
(setq sset (ssget '((0 . "viewport")))) ; Select viewports
(setq num 0)
;; Loop through selected viewports
(repeat (sslength sset)
(setq vprt (cdr (assoc 69 (entget (ssname sset num))))) ; Get viewport number
(if (/= vprt 1)
(progn
(command "mspace")
(command "cvport" vprt)
(command "vplayer" "f" "*" "c" "") ; Freeze all layers initially
;; Retrieve all layers from the drawing
(setq allLayers (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
;; Loop through each layer in the drawing
(vlax-for layerObj allLayers
(setq layerName (vla-get-name layerObj)) ; Get the layer name
;; Thaw the layer only if it's in the allowed list or an Xref layer
(if (or (member (strcase layerName) laylist)
(member layerName xrefLayers)) ; Thaw if it's an Xref layer
(progn
(princ (strcat "\nThawing layer: " layerName)) ; Debug message
(command "vplayer" "t" layerName "c" "") ; Thaw the layer in the viewport
)
)
) ; End vlax-for
) ; End progn
) ; End if
(setq num (1+ num)) ; Increment viewport index
) ; End repeat
;; Switch back to Paper Space and zoom to extents
(command "pspace")
(command "zoom" "e")
(setvar "CMDECHO" 1)
(princ "\nUnfreeze Xref Layers ")
(princ) ; Exit quietly
) ; End defun