PDA

View Full Version : Need Help Deleting "Named Layer Filters"



rabitsarchitects
2004-06-07, 09:02 PM
Does anybody have a LISP routine or anything else that I could use to delete "Named Layer Filters ??

I'm finding drawings with Hundreds maybe Thousands of Named Layer Filters. They are all useless. They are just junk brought over from previous drawings. I deleted the Layer filters from one drawing and it dropped the file size by over 500k. If I can find something to run on all our drawings this would free up an enormous amount of space...\

Thanks for any help you can give...

Rob G.

RobertB
2004-06-07, 10:13 PM
I have posted this code in several places; I guess I should here also!


;|

Written by: R. Robert Bell
Purpose: Allows the user to enter a wildcard string to keep any matching filters.
Sample string: "`#*,MW*" will keep all filters beginning with a "#" or "MW"

Copyright © 2004 by R. Robert Bell

|;

(defun rrbI:LayerFiltersDelete (strKeepWC / objXDict)
;; This function insures that an Extension Dictionary exists, and works on both locations for layer filters
(vl-load-com) ; load ActiveX if needed
(vl-catch-all-apply ; trap error if no extension dictionary
(function
(lambda ()
(setq objXDict (vla-GetExtensionDictionary ; bind dictionary to variable
(vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))))))))
(cond (objXDict ; if the extension dictionary exists
(or ; use OR to return T for success
(rrbI:DeleteAllXRecs objXDict "ACAD_LAYERFILTERS" strKeepWC) ; pre-2005 layer filters
(rrbI:DeleteAllXRecs objXDict "AcLyDictionary" strKeepWC))))) ; 2005 layer filters

(defun rrbI:DeleteAllXRecs (objXDict dictName strKeepWC / objDict i)
;; This function performs the chore of deleting each filer that doesn't match the wildcard
(vl-catch-all-apply ; trap errors
(function
(lambda ()
(setq objDict (vla-Item objXDict dictName)) ; get layer filters dictionary
(vlax-for objXRec objDict ; loop thru all XRecords in the dictionary
(cond ((not (and strKeepWC (wcmatch (vla-Get-Name objXRec) strKeepWC))) ; if deleting all filters, or current doesn't match wildcard
(setq i (1+ (cond (i) ; increment counter
(0)))) ; initialize counter
(vla-Delete objXRec))))))) ; delete filter
(cond (i (princ (strcat "\n" (itoa i) " filters deleted."))))) ; if counter is bound, report number of filters deleted

(defun C:LFD (/ inpKeep)
;; Main command-line function
(setq inpKeep (getstring
"\nWildcard mask for filters to keep, or <Enter> to delete all: "))
(rrbI:LayerFiltersDelete (cond ((/= inpKeep "") inpKeep))) ; pass nil to subr if user hit <Enter>
(princ)) ; clean exit

CADdancer
2004-06-18, 05:25 PM
Rob:

I have used this code to delete all of the layer filters on our drawings. It works well and is very fast.


;;;;;;Start Of Code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;
;;;;;;DELETE LAYER FILTERS
;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun C:LFD ()
(vl-Load-Com)
(vl-Catch-All-Apply
'(lambda ()
(vla-Remove (vla-GetExtensionDictionary
(vla-Get-Layers
(vla-Get-ActiveDocument
(vlax-Get-Acad-Object))))
"ACAD_LAYERFILTERS")))

(princ "\n...")
(princ "\n...All Layer Filters Have Been Deleted...")
(princ)

)
;;;;;;End Of Code

I hope you can find this helpful.

Regards,
Vince

RobertB
2004-06-19, 06:47 PM
Vince,

Your version of my code is out of date. Please see my post in this thread for a new version.

jetman
2004-09-23, 03:55 PM
Free download of CDG Purge developed by the CAD Development Group, LLP will allow you to purge a number of different things from your drawings, including any unused layer filters. Check it out. I use it all the time, so much that I made a tool button for it.

jkramer
2004-09-28, 04:15 PM
Vince,

Your version of my code is out of date. Please see my post in this thread for a new version.

Robert,

I have tried using yours and Vince's code and yours gives me some problems (but Vince's works). It asks a question that requires an "<enter> to delete all" and then I have to regen my drawing to get the layer filters to actually go away. (The layerfiltersdelete is an unknown command, so the only way it works is with LFD.)

What is out of date about Vince's, and why is yours not working for me?

Thank you,
Jessica

jpaulsen
2004-11-08, 11:16 PM
I did some experimenting with both routines and this is what I found. I tried them in the 2002 versions of LDT / Map with SP1 and LDT / Map 2005 SP1.

The long version works great in 2005 and with limited testing in 2002 it seems to work fine there too.

The short routine will not delete layer filters created in 2005 or layer filters created in 2002 that are recognized by 2005. In other words, if they show up in the layer filter list in 2005 the short version would not delete them.

However, there is still a use for the short version in 2005. I found that in some drawings the layer drop-down list on the Layer toolbar is very slow. Running the short version fixes this problem. For more info on the slow drop-down see this thread (http://forums.augi.com/showthread.php?t=10032&highlight=layer+drop).

P.S. I forgot to mention two other things about the long routine. The wild card functionality is case sensitive. Also the routine does not appear to delete any layer filters if one or more were created in that drawing session.

roy.75262
2004-12-17, 06:00 PM
This routing rocks!. Thank you all.

justin.d.ehart
2005-01-17, 11:43 PM
I have posted this code in several places; I guess I should here also!


;|

Written by: R. Robert Bell
Purpose: Allows the user to enter a wildcard string to keep any matching filters.
Sample string: "`#*,MW*" will keep all filters beginning with a "#" or "MW"

Copyright © 2004 by R. Robert Bell

|;

(defun rrbI:LayerFiltersDelete (strKeepWC / objXDict)
;; This function insures that an Extension Dictionary exists, and works on both locations for layer filters
(vl-load-com) ; load ActiveX if needed
(vl-catch-all-apply ; trap error if no extension dictionary
(function
(lambda ()
(setq objXDict (vla-GetExtensionDictionary ; bind dictionary to variable
(vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))))))))
(cond (objXDict ; if the extension dictionary exists
(or ; use OR to return T for success
(rrbI:DeleteAllXRecs objXDict "ACAD_LAYERFILTERS" strKeepWC) ; pre-2005 layer filters
(rrbI:DeleteAllXRecs objXDict "AcLyDictionary" strKeepWC))))) ; 2005 layer filters

(defun rrbI:DeleteAllXRecs (objXDict dictName strKeepWC / objDict i)
;; This function performs the chore of deleting each filer that doesn't match the wildcard
(vl-catch-all-apply ; trap errors
(function
(lambda ()
(setq objDict (vla-Item objXDict dictName)) ; get layer filters dictionary
(vlax-for objXRec objDict ; loop thru all XRecords in the dictionary
(cond ((not (and strKeepWC (wcmatch (vla-Get-Name objXRec) strKeepWC))) ; if deleting all filters, or current doesn't match wildcard
(setq i (1+ (cond (i) ; increment counter
(0)))) ; initialize counter
(vla-Delete objXRec))))))) ; delete filter
(cond (i (princ (strcat "\n" (itoa i) " filters deleted."))))) ; if counter is bound, report number of filters deleted

(defun C:LFD (/ inpKeep)
;; Main command-line function
(setq inpKeep (getstring
"\nWildcard mask for filters to keep, or <Enter> to delete all: "))
(rrbI:LayerFiltersDelete (cond ((/= inpKeep "") inpKeep))) ; pass nil to subr if user hit <Enter>
(princ)) ; clean exit

So where do I copy and paste this code to run it? In the MNU file? I am sorry I am new to this particular routine!

thanks in advance
-jde

jkramer
2005-01-18, 01:00 PM
You will want to make this a .lsp file and you will need to go into appload to load it up. "LayerFiltersDelete" without the quotes, is what you would type on the command line to make it work.

Good luck, it works like a charm!

Mike.Perry
2005-01-18, 08:35 PM
"LayerFiltersDelete" without the quotes, is what you would type on the command line to make it work. Hi

If using Robert's code without any modification you will need to type LFD at the AutoCAD Command Line to run the routine.

Have a good one, Mike

WBWINFREY
2005-01-26, 04:24 PM
HOW DO YOU GET A LISP TO RUN WHEN YOU OPEN AUTOCAD. I HAVE THE LAYER FILTER IN STARTUP BUT I STILL HAVE TO MANUALLY START IT.
HELP PLEASE

Glenn Pope
2005-01-26, 05:08 PM
Add this to the lisp file after the routine.

(c:LFD)

CADNate
2005-01-26, 06:10 PM
If you are using AutoCAD 2004 or 2005 if you open your layer manager and go to the list of layer filters there is a delete all option. Depending on how many layer filters you have this may take a few minutes.

caddict
2005-02-01, 12:04 AM
Thanks Vince!

ckluver
2005-03-31, 04:23 PM
Has anyone written a lisp routine to automate the whole process of opening a drawing, deleting all the layer filters, saving and closing the drawing, opening the next drawing, rinse lather repeat. We didn't spot this problem until it had hit a lot of drawings so we need something that we can just set loose in our drawing database.

jhohman
2005-03-31, 07:39 PM
Just wanted to put in my two cents, loading the lisp with every drawing works only when the drawing is opened, certain things within autocad automatically add layer filters, meaning they will still show up when you enter the Layer Manager dialog. To fix the problem, I recoded the macro associated with the Layer Manager button to invode the LFD prior to invoking the Layer Manager, as long as you enter the Layer Manager through the button, the LFD routine will take place where it's needed and remove all layer filters. Hope this helps, for me it saves the LFD keystoke before I invodke the Layer Manager. The macro associated with the button will be (minus quotes) "LFD;;'_layer;".

tyshofner
2005-03-31, 08:45 PM
ckluver,

I would suggest a program called SciptPro, it's a free download from Autodesk's website:

http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=4091678

I use this to automate a number of tasks that need to be performed on multiple drawings. It will process a scipt on any number of drawings. To use a lisp routine in it, just make sure that the routine you want to use is auto-loading at AutoCAD start-up, then write a script that invokes the command, and voila!

It's also nice that it alerts you to any errors that may have occured while it was processing, and it generates a log file that traps the entire command line sequence for each drawing that is processed. ;-)

Ty :mrgreen:

Julesagain
2006-09-06, 03:39 PM
I have posted this code in several places; I guess I should here also!

Thank you, Bless you! for this quick solution to a problem that has been plaguing me for a while! I don't think what I'm seeing is just leftover layer filter junk from previous drawings, I think its a bug. I'm using several versions of AutoCAD and AcadLT, to keep up with drawings I get from customers. I have gotten several drawings from several widely scattered customers all over the country, who are not connected with each other. However, some of their drawings have literally hundreds of layer filters, with the same names in them, from customer to customer, such as NO F***ING XREFS! and other equally lovely sentiments. One particularly knotty problem in several drawings had ANSI characters in the layer filter names, which would cause ACAD to completely hang up and check out when I would go down the list deleting as I went. Massive frustration. I was beginning to think it was me, until I opened them up on a completely different company's computer and saw the same thing. Anyone else ever seen this?
Anyway, many thanks for an easy and effective solution to something that was driving me crazy, since most of what I do with these drawings is turn things off in the layer dialog, and it was S L O W and arduous to wade through all that garbage.
Julie Walker
Georgia Trane

Julesagain
2006-09-06, 03:49 PM
If you are using AutoCAD 2004 or 2005 if you open your layer manager and go to the list of layer filters there is a delete all option. Depending on how many layer filters you have this may take a few minutes.

The problem with this is if you have the hundreds of filters problem, AutoCAD can get hung up trying to delete them all, or in the case of the ANSI characters in the filter names, that will lock up the 'Delete All' command. I have tried that numerous times before I realized something else was going on. The LSP routine shown above worked beautifully.

Julie Walker
Georgia Trane