Jump to content

Layer Properties Filters


tzframpton

Recommended Posts

Just out of curiosity, where could I look to reference any functionality with Layer Properties Filters for some customizations? Thanks in advance. :)

Link to comment
Share on other sites

  • Replies 20
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    8

  • Tharwat

    5

  • tzframpton

    4

  • harrison-matt

    2

Top Posters In This Topic

Posted Images

Hi Styke,

 

Layer Property Filters are stored in the ACAD_LAYERFILTERS Dictionary, which resides in the Extension Dictionary of the Layer Table.

 

If you need assistance accessing the above location, I'll provide an example :)

 

Lee

Link to comment
Share on other sites

A quickly written example, this will get the entity name of the ACAD_LAYERFILTERS Dictionary, (if it exists):

 

(cdr
 (assoc -1
   (dictsearch
     (cdr
       (assoc 360
         (entget
           (cdr
             (assoc 330
               (entget (tblobjname "LAYER" "0"))
             )
           )
         )
       )
     )
     "ACAD_LAYERFILTERS"
   )
 )
)

From here you could use such functions as dictsearch, dictadd, dictremove to manipulate the items (XRecords) contained in the dictionary.

Link to comment
Share on other sites

Lee . That gives a bad argument type besides that the (assoc 360 .... is not available within the layer name "0" 's codes .

 

; error: bad argument type: lentityp nil

Here is the dxf return codes by the function *entget* for "0" layer .

 

((-1 . ) (0 . "TABLE") (2 . "LAYER") (330 . ) (5 . "2") (100 . "AcDbSymbolTable") (70 . 3))

Link to comment
Share on other sites

Lee . That gives a bad argument type besides that the (assoc 360 .... is not available within the layer name "0" 's codes .

 

You must've tested in a drawing for which there is no Layer Extension Dictionary. The DXF 360 group points to a hard owner id for the Extension Dictionary (if there is one). Note that I am not querying the extension dictionary data for layer "0", but for the layer table itself.

Link to comment
Share on other sites

Here is a more complete example, to retrieve a specific layer filter:

 

(defun getlayerfilter ( filter / dict )
 (if
   (and
     (setq dict
       (cdr
         (assoc 360
           (entget
             (cdr
               (assoc 330
                 (entget (tblobjname "LAYER" "0"))
               )
             )
           )
         )
       )
     )
     (setq dict
       (cdr
         (assoc -1
           (dictsearch dict "ACAD_LAYERFILTERS")
         )
       )
     )
   )
   (dictsearch dict filter)
 )
)

 

Call it with the name of the Layer Filter:

 

(getlayerfilter "YourLayerFilter")

Link to comment
Share on other sites

That's right , there was no Layer Filter in the tested drawing .

 

I am haven't used to deal with Layer filters because all contractor that our company dealing with are not using filters and the

majority not following the layer name in drafting either, which kept me stick with layer dialog box only . :D

 

So after adding a filter to the drawing i got this which I think it is empty ...:unsure:

((-1 . ) (0 . "XRECORD") (5 . "49A5") (102 . "{ACAD_REACTORS") (330 . ) (102 . "}") (330 . ) (100 . "AcDbXrecord") (280 . 1) (1 . "Tharwat") (1 . "*") (1 . "*") (1 . "*") (70 . 0) (1 . "*") (1 . "*"))

 

Thanks a lot .

Link to comment
Share on other sites

To demonstrate a little more, here is an example of adding a new Layer Property Filter (XRecord) to the ACAD_LAYERFILTERS Dictionary. The code will also construct the ACAD_LAYERFILTERS Dictionary if it doesn't exist (i.e. if no Layer Property Filters have been added to the drawing yet).

 

(defun test ( filter / dict xdict )
 (if
   (and
     (setq xdict
       (cdr
         (assoc 360
           (entget
             (cdr
               (assoc 330
                 (entget (tblobjname "LAYER" "0"))
               )
             )
           )
         )
       )
     )
     (or
       (setq dict
         (cdr
           (assoc -1
             (dictsearch xdict "ACAD_LAYERFILTERS")
           )
         )
       )
       (setq dict
         (dictadd xdict "ACAD_LAYERFILTERS"
           (entmakex
            '(
               (0 . "DICTIONARY")
               (100 . "AcDbDictionary")
               (280 . 0)
               (281 . 1)
             )
           )
         )
       )
     )
     (not (dictsearch dict filter))
   )
   (dictadd dict filter
     (entmakex
       (list
         (cons 0 "XRECORD")
         (cons 100 "AcDbXrecord")
         (cons 280 1)
         (cons 1 filter)
         (cons 1 "#*")
         (cons 1 "3")
         (cons 1 "*")
         (cons 70 768)
         (cons 1 "*")
         (cons 1 "*")
         (list -3
           (list "ACAD"
             (cons 1000 "( NAME== \"#*\" ) and ( COLOR== \"3\" ) and LOCKED == \"FALSE\"")
           )
         )
       )
     )
   )
 )
)

 

For clarity, I have hard-coded the Layer Filter properties into the code, so that the function may be called with just the layer filter name, i.e.:

 

(test "MyFilter")

 

A new Layer Filter will be added to the Dictionary if the supplied name (above, "MyFilter") isn't already present as a Layer Filter in the drawing. The added Layer Filter will allow layers for which the name matches "#*", the layer colour is "3" and the layer is unlocked (three arbitrarily chosen properties for a demonstration).

 

Note that in addition to the multiple DXF group 1 codes which store the properties for name, colour, linetype etc., the xRecord also requires xData storing a string describing the property values.

 

The DXF codes for the Layer Filters are undocumented, but I have collected some information along the way:

 

 
;; Layer Filter XRecord Data

The following list details the various DXF codes and values contained in the Xrecord:

1 Name of Filter
1 Layer Name
1 Color
1 Linetype
70 (Please refer further below)
1 Lineweight
1 PlotStyle

The 70 DXF code can contain one of the following numbers or an addition of them:

ON/OFF
On 1
Off 3

FREEZE/THAW
Freeze 4
Thaw 12

CURRENT VPORT
Freeze 16
Thaw 48

NEW VPORT
Freeze 64
Thaw 192

LOCK/UNLOCK
Lock 256
UnLock 768

PLOT
Plot 1024
Don't Plot 3072 

 

I hope this helps.

Link to comment
Share on other sites

So after adding a filter to the drawing i got this which I think it is empty ...:unsure:

 

That is the xRecord data as returned by dictsearch for the Layer Filter you have added (I assume you have called it "Tharwat").

 

You can get the full list of DXF groups for the XRecord using:

 

(entget (cdr (assoc -1 (getlayerfilter "Tharwat"))) '("*"))

Link to comment
Share on other sites

The DXF codes for the Layer Filters are undocumented, but I have collected some information along the way:

 

That's really a very kind of you , besides what you have worked on to show us examples to learn .

 

I think I have to start studying about dictionaries in general to be able to handle or to understand things like you have brought deeply .

 

Highly appreciated.

 

Tharwat

Link to comment
Share on other sites

That's really a very kind of you , besides what you have worked on to show us examples to learn .

 

I think I have to start studying about dictionaries in general to be able to handle or to understand things like you have brought deeply .

 

Thanks Tharwat, you're welcome.

 

Dictionaries can be a very effective method of storing data in a drawing, so knowledge of how to manipulate them is very useful indeed. Furthermore, items such as Layouts, MLeaderStyles, MLineStyles, Plot Styles etc. are all stored in dictionaries, and, as illustrated above, some objects use Extension Dictionaries to store additional data.

 

There are also Visual LISP methods for manipulating Dictionaries* and the XRecords contained therein, but in my opinion these objects are easier manipulated using Vanilla AutoLISP since you can avoid the use of Safearrays & Variants etc.

 

[*See the Dictionaries property of the Document Object, and also the AddObject/GetObject methods of the Dictionary Object (which could be viewed as being analogous to the dictadd/dictsearch functions), following these there are the Get/SetXRecordData methods pertaining to the XRecord Objects, but such methods use the same data structures (DXF groups) as are used by the Vanilla equivalents, although these must then be converted to Variants of Integers and Variants of Variants.]

Link to comment
Share on other sites

  • 3 weeks later...

Lee,

 

I have taken a look at your examples above and familiarized my self with that particular XRECORD, but I am still stuck trying to find out how to add new/see existing sub filters within a filter.

 

Kind Regards,

 

Matt

Link to comment
Share on other sites

Capture.JPGWell, I have currently a filter that filters layer names: M-* & MK-* layers and within that filter i have subfilters that filter layers with *HVAC* and another filter that filters *PIPE* etc. Those subfilters are arranged under the first Mechanical Filter. See the image for more info. Additionally i now have those filter groups & property filters exported to a *.lft file that can be imported into the dialog (only on vertical products, i.e. AutoCAD MEP). I want to have a program that when I insert my layer block the program either inserts the layer filters or creates them.

 

Kind Regards,

 

Matt

Link to comment
Share on other sites

  • 3 years later...

I'd like to add all my layer filter properties with lisp. Copying the properties from the layer filter dialog box works for most. Only ones I cannot figure out are for "Status". They only show as icons. For properties I've tried STATUS==NOT IN USE and STATUS==NOT IN USE and STATUS==Unused. Neither worked.

 

 

 

(getlayerfilter "NODE") and all the ones using NAME property worked great.

(getlayerfilter "All Unused Layers") using Status would not work. Could these be stored in a separate dictionary?

Here is a more complete example, to retrieve a specific layer filter:

 

 

Call it with the name of the Layer Filter:

 

(getlayerfilter "YourLayerFilter")

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...