LISP or other method to freeze/remove layers that are vpfrozen in ALL viewports

LISP or other method to freeze/remove layers that are vpfrozen in ALL viewports

Netelaana
Enthusiast Enthusiast
1,539 Views
3 Replies
Message 1 of 4

LISP or other method to freeze/remove layers that are vpfrozen in ALL viewports

Netelaana
Enthusiast
Enthusiast

I can't seem to find anything like this after scouring the forums, but maybe I missed it.

 

I have many (dozens) of viewports  (each with a unique set of layers frozen) on multiple (20+) paperspace tabs, and I need to remove and/or freeze (in model space) all layers that are vpfrozen in ALL viewports.

 

Basically, if I can't see the layer in paperspace (or through any vp), I need to remove it from the drawing. 

 

Any ideas? Thanks for your thoughts!

0 Likes
Accepted solutions (1)
1,540 Views
3 Replies
Replies (3)
Message 2 of 4

pbejse
Mentor
Mentor

@Netelaana wrote:

Any ideas? Thanks for your thoughts!


You can get inspiration from JTB World : Vplayer.lsp

 

;;; ex. (viewport-frozen-layer-list) -> ("Layer3" "Layer4")
;;; alt. with Express Tools (ACET-VIEWPORT-FROZEN-LAYER-LIST (ACET-CURRENTVIEWPORT-ENAME))
(defun viewport-frozen-layer-list (/ cvp)
... )

Holler if you need help putting this together.

 

 

 

0 Likes
Message 3 of 4

pbejse
Mentor
Mentor
Accepted solution

@pbejse wrote:

 

;;; alt. with Express Tools (ACET-VIEWPORT-FROZEN-LAYER-LIST (ACET-CURRENTVIEWPORT-ENAME))

I opted not to go that route, wher you need to activate the viewports to retrieve the layerlist.

 

 Instead use 

(tblobjname "block" "*PAPER_SPACE")

Try this

(Defun c:DelFrozenAtVp (/ ListVPFreezeLayers _removeduplicates AllFronzenVP
			  aDoc aDocLayers 4deletion f)
;;				pBe MAy 2020					;;
  
;; https://adndevblog.typepad.com/autocad/2012/12/				;;
;; get-the-per-viewport-frozen-layers-for-paper-space-viewports-in-lisp.html	;;
  
(defun ListVPFreezeLayers (/ psEnt ent lst ename _FrzLst)
    (setq psEnt (tblobjname "block" "*PAPER_SPACE"))
    (setq ent (entnext psEnt))
    (setq ent (entnext ent))
    (setq lst (entget ent '("*")))
    (setq ename (cdr (assoc 0 lst)))
    (setq i 0)
    (while (/= ent nil)
      (setq lst (entget ent '("*")))
      (setq ename (cdr (assoc 0 lst)))
      (if (= ename "VIEWPORT")
	(progn
	  (setq	lst (cdadr (assoc -3 lst))
		lst (mapcar 'cdr
			    (Vl-remove-if-not
			      '(lambda (v)
				 (= (car v) 1003)
			       )
			      lst
			    )
		    )
	  )
	  (setq _FrzLst (cons lst _FrzLst ))
	)
      )
      (setq ent (entnext ent))
    )
    _FrzLst
  )
  
  (defun _removeduplicates (lst)
    (if	(car lst)
      (cons (car lst)
	    (_removeduplicates (vl-remove (car lst) (cdr lst)))
      )
    )
  )
  (setq AllFronzenVP nil 4deletion nil)
  (setq	aDoc	   (vla-get-ActiveDocument (vlax-get-acad-object))
	aDocLayers (vla-get-layers aDoc)
  )

  (if
    (foreach itm (layoutlist)
      (setvar 'ctab itm)
      (if (And
	    (ssget "_X" (list '(0 . "VIEWPORT")'(-4 . ">")'(69 . 1)(cons 410 itm)))
	    (setq f (ListVPFreezeLayers))
	    )
	(setq AllFronzenVP (Cons f AllFronzenVP))
      )
      AllFronzenVP
    )
     (progn
       (setq AllFronzenVP (apply 'append AllFronzenVP))
       (foreach	itm (_removeduplicates (apply 'append AllFronzenVP))
	 (if (vl-every '(lambda	(nms)
			  (member itm nms)
			)
		       AllFronzenVP
	     )
	   (setq 4deletion (Cons itm 4deletion))
	 )
       )
       (Foreach	l 4deletion
	 (vla-put-lock (Vla-item aDocLayers l) :vlax-false)
	 (command "_.-laydel" "_N" l "" "_Y")
       )
     )
  )
  (princ)
)

 

HTH

 

 

Message 4 of 4

Netelaana
Enthusiast
Enthusiast

Absolutely wonderful! You have no idea how much time you just saved me. Works perfectly to clean out all the "space junk" after design. 

 

Thanks!!!

0 Likes