Lisp Command to freeze layers in Viewport

Lisp Command to freeze layers in Viewport

joey_rooker
Participant Participant
331 Views
1 Reply
Message 1 of 2

Lisp Command to freeze layers in Viewport

joey_rooker
Participant
Participant

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

 

0 Likes
332 Views
1 Reply
Reply (1)
Message 2 of 2

Moshe-A
Mentor
Mentor

@joey_rooker  hi,

 

Here is what is see (sorry if got it wrong 😀)

 

on line 5 you declare laylist - not xref layers - ok

on lines 36-41 you are collecting all xrefs layers names - ok

on line 61 you are freezeing all vplayers - ok

on 67 your iterating through all layers - ok

on line 71 you are testing if layerName is member of laylist and if it true? you are using vplayer to to thaw a layer that is not an xref, instead use standard layer command.

on line 72 your are testing if layerName is member of xrefLayers and thaw it, that puts you end up thawing all layers collected on line 40

if your attention is to leave some xref layers thawed, where is that layer list?

 

Moshe

 

0 Likes