Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LISP request: create local layer filter

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
barry2104
4046 Views, 12 Replies

LISP request: create local layer filter

Hello everyone!
I often work on drawings which have multiple xrefs, each having up to 100 Layers or more, so the layer manager can be a bit difficult to trawl through to find a local layer to select.
I know how to create a local layer filter using the code ~*|* from the new filter area in layer manager, but I wonder if anyone has/can quickly knock up a code to speed this process up.

 

Ideally all I want to have to type in is: LOCAL
and then the local layer filter would be created, with the filter name being Local-Layers (or similar).

 

any ideas/help muchly appreciated!!

Running AutoCAD Architecture 2020, in German
12 REPLIES 12
Message 2 of 13
Lee_Mac
in reply to: barry2104

Try this quick code:

 

(defun c:local ( / dc fn xd )
    
    (setq fn "Local-Layers") ;; Filter Name
    
    (if
        (and
            (setq xd
                (cdr
                    (assoc 360
                        (entget
                            (cdr
                                (assoc 330
                                    (entget
                                        (tblobjname "layer" "0")
                                    )
                                )
                            )
                        )
                    )
                )
            )
            (or (setq dc (cdr (assoc -1 (dictsearch xd "ACAD_LAYERFILTERS"))))
                (setq dc
                    (dictadd xd "ACAD_LAYERFILTERS"
                        (entmakex
                           '(
                                (000 . "DICTIONARY")
                                (100 . "AcDbDictionary")
                                (280 . 0)
                                (281 . 1)
                            )
                        )
                    )
                )
            )
            (null (dictsearch dc fn))
        )
        (dictadd dc fn
            (entmakex
                (list
                   '(000 . "XRECORD")
                   '(100 . "AcDbXrecord")
                   '(280 . 1)
                    (cons 1 fn)
                   '(001 . "~*|*")
                   '(001 . "*")
                   '(001 . "*")
                   '(070 . 0)
                   '(001 . "*")
                   '(001 . "*")
                   '(-3
                        (
                            "ACAD"
                            (1000 . "( NAME== \"~*|*\" )")
                        )
                    )
                )
            )
        )
    )
    (princ)
)

 

Message 3 of 13
barry2104
in reply to: Lee_Mac

hmm doesn't seem to work/do anything when I type in LOCAL after loading her in... does it work for anyone else out there?
Running AutoCAD Architecture 2020, in German
Message 4 of 13
alanjt_
in reply to: Lee_Mac

FYI, you can also create layer filters from the -layer command.

 

eg.

 

Command: la
-LAYER
Current layer:  "0"
Enter an option 
[?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/Fre
eze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: filter

Current layer filter: "All"

Enter a layer filter option [New/Set/Rename/Edit/Delete/eXit]:

 

Message 5 of 13
Lee_Mac
in reply to: barry2104


@barry2104 wrote:
hmm doesn't seem to work/do anything when I type in LOCAL after loading her in... does it work for anyone else out there?

Does it not create the layer filter as required?

Did you check the Layer Manager after using the program?

Message 6 of 13
barry2104
in reply to: Lee_Mac

aha, got it now. I had the layermanager open to my left as I typed in the new command, but saw nothing new pop up into the filter list.
after posting my response, I realised that the layermanager needs to be CLOSED and then REOPENED for the changes to become apparent.
I'm assuming this closure and reopening cannot be avoid by tweaking the script further?

thanks a lot Lee Mac - you are a wealth of knowledge!
Running AutoCAD Architecture 2020, in German
Message 7 of 13
barry2104
in reply to: barry2104

pinkieed+down+you+sir+deserve+a+medal+_3860f8816df2d314f410257b31f6018d[2].jpg

Running AutoCAD Architecture 2020, in German
Message 8 of 13
Lee_Mac
in reply to: barry2104

Thank Barry Smiley Happy

 

Since I am adding the layer filter XRecord directly to the ACAD_LAYERFILTERS dictionary, it is likely that the Layer Manager would need to be reopened to read any new items from this dictionary.

 

In this case, it may be simpler to follow Alan's suggestion of automating the -LAYER command to create & set the layer filter current, rather than my rather more 'purist' route. Smiley Wink

 

Happy to help.

Message 9 of 13
alanjt_
in reply to: Lee_Mac

  rather than my rather more 'purist' route. Smiley Wink

 

 


*giggle*   

 

 

Message 10 of 13
3wood
in reply to: Lee_Mac

I have tried the code, it creates a new filter but the layer manager and layer toolbar don't work properly. The layer list doesn't update when you click any filter items including filters under xref. Smiley Sad

 

BTW, there are some rouintes in the forum which allow you setup some filter conditions in a txt file. When you open a drawing, the routine can read it and create filters for you.

Message 11 of 13
mpe
Participant
in reply to: barry2104

If I use the -layer command with the filter option to create a property filter, how should I define my filter definition?

For instance if I want all layers from which the name starts with X-.

 

Any tips are very welcome!

 

Regards,

Marcel Pennings

Message 12 of 13
hmsilva
in reply to: mpe

try
(command "-layer" "_filter" "_N" "_P" "" "NAME==\"X-*\"" "MyTestFilter" "")

HTH
Henrique

EESignature

Message 13 of 13
leeraybone
in reply to: barry2104

Hello there,

 

I'm trying to add your suggestions to a lisp routine i use to insert blocks.

 

but i cannot seem to get the layers to add to the group filter

 

The filters are all created fine, it just won't add the layers to the filter.

 

Any ideas?

 

I am using the following

 

(command "-layer" "_filter" "_N" "_G" "Formwork" "M_PANEL" "EcoAS" "")

(command "-layer" "_filter" "_S" "All" "" "")

 

or

 

(command "-layer" "Fil" "N" "G" masterGRPname eLay subGRPname "")

(command "-layer" "_filter" "_S" "All" "" "")

 

Regards,

 

 

Lee

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost