Delete all frozen layers

Delete all frozen layers

Anonymous
Not applicable
10,766 Views
11 Replies
Message 1 of 12

Delete all frozen layers

Anonymous
Not applicable

Hi, I am pretty new to lisp and I was wondering if there was a way to go through all layers, check if it is frozen, and if it is delete it. I already have a function that freezes the layers I want deleted specifically. I was looking into using 

(vlax-for Lay (vla-get-Layers ActDoc)
        (if
                (= (vla-get-Freeze Lay) ':vlax-true)

to see if it is frozen and "laydel" to delete the layer, but I am unsure how to proceed from here. Any help would be welcome.

Thanks!

0 Likes
Accepted solutions (1)
10,767 Views
11 Replies
Replies (11)
Message 2 of 12

pendean
Community Legend
Community Legend
Q: why don't you just WBLOCK out the drawing to create a new file once all of these layers are frozen? same end result, just quicker.



Message 3 of 12

Anonymous
Not applicable

Hi Pendean,

Does WBLOCKing the drawing remove the frozen layers? I tried it myself and it didn't work. I need to remove the frozen layers. I did also try to WBLOCK objects and manually selected the layer, which worked, but I am unsure on how to recreate that in a lisp.

Thanks for telling me about this though! 

 

 

0 Likes
Message 4 of 12

dbhunia
Advisor
Advisor
Accepted solution

Try like this 

 

(setq lay_Col (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))))
(vlax-for Lay lay_Col
	(if (= (vla-get-Freeze Lay) :vlax-true)
		(if (= (vla-get-Lock Lay) :vlax-false)
			(vl-cmdf "_.-laydel" "_N" (vla-get-Name Lay) "" "_Y")
		)
	)
)

 

For more see This


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 5 of 12

ronjonp
Mentor
Mentor

I've been using this one for years:

(defun c:frzlaydel (/ doc err fzl msg n n2)
  ;; RJP » 2019-07-19
  (setq err 0)
  (setq n 0)
  (setq n2 0)
  ;; Get frozen layers
  (vlax-for lay	(vla-get-layers (setq doc (vla-get-activedocument (vlax-get-acad-object))))
    (and (not (wcmatch (vla-get-name lay) "*|*"))
	 (or (eq (vla-get-freeze lay) :vlax-true) (eq (vla-get-layeron lay) :vlax-false))
	 (setq fzl (cons lay fzl))
	 (vla-put-lock lay :vlax-false)
    )
  )
  (if (setq fzl (mapcar 'vla-get-name fzl))
    (progn (vlax-for b1	(vla-get-blocks doc)
	     (vlax-for b2 b1
	       (if (vl-position (vla-get-layer b2) fzl)
		 (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-delete (list b2)))
		   (setq err (1+ err))
		   (setq n (1+ n))
		 )
		 (setq n2 (1+ n2))
	       )
	     )
	   )
	   (setq msg (strcat (strcat (itoa err) " errors deleting objects...\n")
			     (strcat (itoa n) " objects were deleted, ")
			     (strcat (itoa n2) " objects were ignored.")
		     )
	   )
	   (if (zerop (getvar 'cmdactive))
	     (alert msg)
	     (princ msg)
	   )
    )
    (princ (strcat "\nNo eligible layers found."))
  )
  (princ)
)
Message 6 of 12

Anonymous
Not applicable

dbhunia Your code worked great! I was able to delete all the frozen layers. rperez I am not sure if I did something incorrectly, but it only deleted some of the objects, ignored most of them, and did not delete the layers. Since it worked for you, I am pretty sure it is my fault, but it does not matter anymore. Thanks everyone for helping me with this!

I have another question, which might be dumb. Is there a way to remove x-ref layers in the same way? 

 

0 Likes
Message 7 of 12

ronjonp
Mentor
Mentor

@Anonymous wrote:

dbhunia Your code worked great! I was able to delete all the frozen layers. rperez I am not sure if I did something incorrectly, but it only deleted some of the objects, ignored most of them, and did not delete the layers. Since it worked for you, I am pretty sure it is my fault, but it does not matter anymore. Thanks everyone for helping me with this!

I have another question, which might be dumb. Is there a way to remove x-ref layers in the same way? 

 


Might just need to add a purge at the end of the code to remove the layers. You cannot remove xref layers.

 

Tried to modify the code above but missed the magical 30 minute mark ;/ .. so here it is again:

(defun c:frzlaydel (/ doc err fzl msg n n2)
  ;; RJP » 2019-07-19
  (setq err 0)
  (setq n 0)
  (setq n2 0)
  ;; Get frozen layers
  (vlax-for lay	(vla-get-layers (setq doc (vla-get-activedocument (vlax-get-acad-object))))
    (and (not (wcmatch (vla-get-name lay) "*|*"))
	 (or (eq (vla-get-freeze lay) :vlax-true) (eq (vla-get-layeron lay) :vlax-false))
	 (setq fzl (cons lay fzl))
	 (vla-put-lock lay :vlax-false)
    )
  )
  (if (setq fzl (mapcar 'vla-get-name fzl))
    (progn (vlax-for b1	(vla-get-blocks doc)
	     (vlax-for b2 b1
	       (if (vl-position (vla-get-layer b2) fzl)
		 (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-delete (list b2)))
		   (setq err (1+ err))
		   (setq n (1+ n))
		 )
		 (setq n2 (1+ n2))
	       )
	     )
	   )
	   (setq msg (strcat (strcat (itoa err) " errors deleting objects...\n")
			     (strcat (itoa n) " objects were deleted, ")
			     (strcat (itoa n2) " objects were ignored.")
		     )
	   )
	   (if (zerop (getvar 'cmdactive))
	     (alert msg)
	     (princ msg)
	   )
	   (repeat 2 (vla-purgeall doc))
    )
    (princ (strcat "\nNo eligible layers found."))
  )
  (princ)
)
Message 8 of 12

pendean
Community Legend
Community Legend
Late response: Frozen layers are always removed in WBLOCK unless you have content that still use those layers.
0 Likes
Message 9 of 12

josue777torsan
Advocate
Advocate
How can I invoque the command after save it as .lsp?
Architect, CAD Manager in Mexico City
0 Likes
Message 10 of 12

Kent1Cooper
Consultant
Consultant

@josue777torsan wrote:
How can I invoque the command after save it as .lsp?

Always the part right after (defun C:

 

(defun C:ThisIsTheCommandName (....

 

[the C can be capitalized or not, and the command name is not case-sensitive]

Kent Cooper, AIA
0 Likes
Message 11 of 12

josue777torsan
Advocate
Advocate

Yes, but I do not see the defun c: in the code  I quoted 

 

Thanks Kent

Architect, CAD Manager in Mexico City
0 Likes
Message 12 of 12

aadish_rahman
Contributor
Contributor

thank you very much

0 Likes