PDA

View Full Version : Delete / Remove all frozen and_or turned off layers?


stephen.coff
2007-03-24, 07:29 AM
Guys,
In the process of making a lisp routine that strips and prepares the Architects drawing for use as a background xref.
I have most things sorted, it renames the files and saves it in it's required place. It thens follows on to removal of dimensions, solids and hatching etc
It creates 1 layer name "Architectural" and then places everything on that layer and purges and audits. I am pretty happy with that though have noticed a couple of small things that i am not sure how to do. Often people have info on drawings that they don't want seen so they freeze the layer or turn it off. With lisp, how can i remove only the frozen or turned off layers ? I need to do this because I am ending up with this **** exploded on the drawings and then all on the same layer, not good.

If anyone could assist I would be most grateful.

regards

Stephen

aaronic_abacus
2007-03-25, 02:25 AM
;This autolisp program deletes all frozen entities and purges their layers.



(DEFUN C:EFEL ()
(PROMPT "\n*ERASE ALL FROZEN ENTITIES BY LAYER(with purge)* ")
(SETQ LTSRL 1)
(SETQ LP 1)
(WHILE LP
(SETQ LTS (TBLNEXT "LAYER" LTSRL))
(SETQ LTSRL NIL)
(SETQ LTSF (CDR (ASSOC 70 LTS)))
(SETQ LTST (CDR (ASSOC 2 LTS)))
(SETQ LTSTF (LIST (CONS 8 LTST)))
(IF (= LTSF 1)
(PROGN
(SETQ EBS (SSGET "X" LTSTF))
(COMMAND "ERASE" EBS "")
(COMMAND "LAYER" "T" "0" "S" "0" "")
(COMMAND "PURGE" "LA" LTST "N")
));END PROGN/IF LTSF
(IF (= LTS NIL) (SETQ LP NIL))
);END LP
(PRINC)
);END EFEL

stephen.coff
2007-03-25, 06:02 AM
Once again,
Aarinic, greatly appreciated.

regards

Stephen

stephen.coff
2007-03-25, 07:21 AM
Aaronic,
I tried it on an Architectural I had been using recently.
I exploded the drawing a couple of times as it was a nested block. I ran the routine though something is quite right, it keeps running through repeating the same error.

I have attached the drawing.

Reagrds

Stephen

aaronic_abacus
2007-03-25, 08:27 PM
;Below is EFEL.LSP revised to account for an empty selection set.
;The program will not work with nested entities
; where the block is on an thawed layer and the nested entities on a frozen layer.



(DEFUN C:EFEL ()
(PROMPT "\n*ERASE ALL FROZEN ENTITIES BY LAYER(with purge)* ")
(SETQ LTSRL 1)
(SETQ LP 1)
(WHILE LP
(SETQ LTS (TBLNEXT "LAYER" LTSRL))
(SETQ LTSRL NIL)
(SETQ LTSF (CDR (ASSOC 70 LTS)))
(SETQ LTST (CDR (ASSOC 2 LTS)))
(SETQ LTSTF (LIST (CONS 8 LTST)))
(IF (= LTSF 1)
(PROGN
(SETQ EBS (SSGET "X" LTSTF))
(IF (/= EBS NIL) (COMMAND "ERASE" EBS ""))
(COMMAND "PURGE" "LA" LTST "N")
));END PROGN/IF LTSF
(IF (= LTS NIL) (SETQ LP NIL))
);END LP
(PRINC)
);END EFEL

stephen.coff
2007-03-25, 11:28 PM
Aaronic,
Thanks, grately appreciated.

Stephen

stephen.coff
2007-03-25, 11:35 PM
Guys,
Does anyone have anything elese ? No disrespect Aaronic though this routine doesn't seem to do what i am looking for.
I want to be able to remove all frozen and turn off layers with all there content.

Could someone tell me how I make a selection set with all the frozen and turned off objects ?

Regrads

Stephen

miff
2007-03-26, 04:28 AM
Hi Stephen, give this a try...

(defun c:delfrzoff (/ blocks doc ent idx layers lays2delete ss)
(vl-load-com)
(setq doc (vla-get-activedocument (vlax-get-acad-object))
layers (vla-get-layers doc)
blocks (vla-get-blocks doc)
idx -1
)
(vlax-for lay layers
(if (or (eq (vla-get-layeron lay) :vlax-false)
(eq (vla-get-freeze lay) :vlax-true)
)
(progn
(vla-put-lock lay :vlax-false)
(if lays2delete
(setq lays2delete (strcat lays2delete "," (vla-get-name lay)))
(setq lays2delete (vla-get-name lay))
)
)
)
)
(if (and lays2delete
(setq ss (ssget "x" (list (cons 8 lays2delete))))
)
(progn
(while (setq ent (ssname ss (setq idx (1+ idx))))
(vla-delete (vlax-ename->vla-object ent))
)
)
)
(princ (strcat "\nDone....deleted " (itoa (1+ idx)) " entities from the drawing."))
(princ)
)

HTH,
Jeff

stephen.coff
2007-03-28, 12:55 AM
Aaronic,
My apologies. I have come to realise that both routines do the same thing which is what I had asked for. For some reason they don't seem to properly purge the layers after removing the objects which was the reason for my comments. I ran both routines and with they layers off or frozen and then checked and layers were still showing as being there. It wasn't until I turned everything on that I realised the objects etc had actually been removed thus the routine just dosen't seem to purge it correctly.
Thank you both for your help and efforts.

Stephen

pmedina
2007-03-28, 02:16 PM
I am a weak lisp writer, but i could suggest you lock the layers you want to save, then turn on and thaw everything. Then do an erase all and follow up with a purge, audit (Dont forget to purge your reg-apps)

jmcshane
2007-03-28, 03:39 PM
For some reason they don't seem to properly purge the layers after removing the objects which was the reason for my comments. I ran both routines and with they layers off or frozen and then checked and layers were still showing as being there. It wasn't until I turned everything on that I realised the objects etc had actually been removed thus the routine just dosen't seem to purge it correctly.


Stephen



(vlax-for lay layers
(if
(eq (vla-get-freeze lay) :vlax-true)
(vla-put-freeze lay :vlax-false)
)
)
(vlax-for lay layers
(vla-put-layeron lay :vlax-true)
)

(vla-purgeall Doc)


(princ (strcat "\nDone....deleted " (itoa (1+ idx)) " entities from the drawing."))
(princ)
)


I stuck this at the bottem of Miff's routine and it seemed to work.
I'm sure it could be written more eloquently, and hopefully somebody out therewill do just that so we could see how it can be done.

John

miff
2007-03-28, 06:01 PM
First, I didn't notice that you also wanted the layers purged, sorry about that. Second, in light of that, there are more things that would need to be checked to truly be able to purge them.....I don't have the time right now to code this, but the idea wouold be to attempt to delete the layers after you delete the entities on them. So I'd add a variable, layobjlist, to place the (vla-object) of the layers we are deleting in the code where we get the name, then after this code:

(while (setq ent (ssname ss (setq idx (1+ idx))))
(vla-delete (vlax-ename->vla-object ent))
)

you'd add something like this:

(mapcar '(lambda (x)
(setq tmperr (vl-catch-all-apply 'vla-delete x))
(if (vl-catch-all-error-p tmperr)
(setq notdeleted (cons x notdeleted))
)
)
layoblist)

Then, if the variable 'notdeleted' is not nil, those layers are in use by a DimStyle, frozen in a PS viewport, used by an object in a block, etc. and need to be dealt with in other ways.

stephen.coff
2007-03-29, 11:16 AM
Guys,
This might sound rude though not meant to be. I want to add this into another routine I have made for stripping Architects drawings. I have writen it in lisp and wondered if anyone could write this for me likewise ?

Stephen

miff
2007-03-29, 07:54 PM
Uh, everything that's been posted HAS been in lisp......notice all the (....)'s? :-)

What Autocad version are you using, Stephen?

How about posting what you've written so we can see how to best incorporate it with what we've shown?