Jump to content

Recommended Posts

Posted

Hi all,

is there a way to define a property filter for lyers to exclude some patterns?

 

(Assume you want to hide layers starting with "3D ", which the matching pattern in wcmatch function is "~3D *"...)

 

Any help is appreciated.

Posted

Here is an example for you to consider:

 

([color=BLUE]defun[/color] c:addfilter ( [color=BLUE]/[/color] dc fn xd )
   
   ([color=BLUE]setq[/color] fn [color=MAROON]"No 3D"[/color])
   
   ([color=BLUE]if[/color]
       ([color=BLUE]and[/color]
           ([color=BLUE]setq[/color] xd
               ([color=BLUE]cdr[/color]
                   ([color=BLUE]assoc[/color] 360
                       ([color=BLUE]entget[/color]
                           ([color=BLUE]cdr[/color]
                               ([color=BLUE]assoc[/color] 330
                                   ([color=BLUE]entget[/color]
                                       ([color=BLUE]tblobjname[/color] [color=MAROON]"LAYER"[/color] [color=MAROON]"0"[/color])
                                   )
                               )
                           )
                       )
                   )
               )
           )
           ([color=BLUE]or[/color] ([color=BLUE]setq[/color] dc ([color=BLUE]cdr[/color] ([color=BLUE]assoc[/color] -1 ([color=BLUE]dictsearch[/color] xd [color=MAROON]"ACAD_LAYERFILTERS"[/color]))))
               ([color=BLUE]setq[/color] dc
                   ([color=BLUE]dictadd[/color] xd [color=MAROON]"ACAD_LAYERFILTERS"[/color]
                       ([color=BLUE]entmakex[/color]
                          '(
                               (0 . [color=MAROON]"DICTIONARY"[/color])
                               (100 . [color=MAROON]"AcDbDictionary"[/color])
                               (280 . 0)
                               (281 . 1)
                           )
                       )
                   )
               )
           )
           ([color=BLUE]null[/color] ([color=BLUE]dictsearch[/color] dc fn))
       )
       ([color=BLUE]dictadd[/color] dc fn
           ([color=BLUE]entmakex[/color]
               ([color=BLUE]list[/color]
                  '(0 . [color=MAROON]"XRECORD"[/color])
                  '(100 . [color=MAROON]"AcDbXrecord"[/color])
                  '(280 . 1)
                   ([color=BLUE]cons[/color] 1 fn)
                  '(1 . [color=MAROON]"~3D *"[/color])
                  '(1 . [color=MAROON]"*"[/color])
                  '(1 . [color=MAROON]"*"[/color])
                  '(70 . 0)
                  '(1 . [color=MAROON]"*"[/color])
                  '(1 . [color=MAROON]"*"[/color])
                  '(-3
                       (
                           [color=MAROON]"ACAD"[/color]
                           (1000 . [color=MAROON]"( NAME== \"~3D *\" )"[/color])
                       )
                   )
               )
           )
       )
   )
   ([color=BLUE]princ[/color])
)

Posted

Lee, thank you very much.

 

It is very useful and absolutely the code I requested, but I encountered a problem revising your program to define a filter to include some pattern and also exclude some other.

 

For example, when I define a filter to include "2D *" and exclude "3D ", I chaged the pattern "~3D *,2D *", but it doesn't work.

What is wrong with my revision?

 

 

Posted
For example, when I define a filter to include "2D *" and exclude "3D ", I chaged the pattern "~3D *,2D *", but it doesn't work.

 

To my knowledge, I don't think the 'Name' field of a Layer Property Filter can process wildcards with multiple patterns (each pattern must be entered as a new rule for the filter, and the rules are then processed using an inclusive OR logic gate).

 

However, since a layer name cannot start with both "2D *" and "3D *", your filter only needs to be "2D *" to only include layers with this prefix, hence automatically excluding those prefixed with "3D *".

Posted

Its a bit old fashioned but you can use -LA to do the same. -la off 2d* T 3d* on 1d*

Posted (edited)
To my knowledge, I don't think the 'Name' field of a Layer Property Filter can process wildcards with multiple patterns (each pattern must be entered as a new rule for the filter, and the rules are then processed using an inclusive OR logic gate).

 

However, since a layer name cannot start with both "2D *" and "3D *", your filter only needs to be "2D *" to only include layers with this prefix, hence automatically excluding those prefixed with "3D *".

 

Lee, you are right. My example was not a good one. Let me explain my problem step by step:

 

First of all, I want to confirm that your code is fine and perhaps the problem is due to a bug of AutoCAD.

 

 

 

Assume you have a drawing including these layers:

  • "3D Door-Architectural"
  • "3D Window-Architectural"
  • "2D Door-Architectural"
  • "2D Window-Architectural"
  • "3D HVAC-Mechanical"
  • "2D HVAC-Mechanical"
  • "Door-Architectural"
  • "Window-Architectural"
  • "HVAC-Mechanical"
  • "Column-Structural"
  • "Beam-Structural"
  • ...

1- To define a filter to show layers matching "*-Architectural", using "*-Architectural", your code works fine.

 

2- To define a filter to hide layers matching "*-Architectural", using "~*-Architectural", the code works fine.

 

3- To define a filter to show layers matching "*-Architectural" OR "*-Structural", using "*-Architectural,*-Structural", the code works fine.

 

4- To define a filter to show layers matching "*-Architectural" OR "3D *", using "*-Architectural,3D *", the code doesn't work as desired.

 

5- To define a filter to hide layers matching "*-Architectural" OR "*-Structural", using "~*-Architectural,~*-Structural", the code doesn't work.

 

6- To define a filter to hide layers matching "*-Architectural" OR show layers matching "3D *", using "~*-Architectural,3D *", the code doesn't work.

(???)

 

Any suggestion?

 

Layer Filter Example.dwg

Edited by Ahankhah
Posted (edited)
Its a bit old fashioned but you can use -LA to do the same. -la off 2d* T 3d* on 1d*

BIGAL, I don't want to turn layers off. Indeed layer filters hide layers from Layer "Pull down menu" or "Layer window".

Edited by Ahankhah
Posted
4- To define a filter to show layers matching "*-Architectural" OR "3D *", using "*-Architectural,3D *", the code doesn't work as desired.

 

For this filter in your drawing you have mispelled 'Architectural' as 'Aechitectural'

 

5- To define a filter to hide layers matching "*-Architectural" OR "*-Structural", using "~*-Architectural,~*-Structural", the code doesn't work.

 

Since each rule in the filter is applied using OR logic, the '-Structural' layers will be permitted by the '~*-Architectural' rule, and similarly the '-Architectural' layers will be permitted by the '~*-Structural' rule, hence both will remain.

 

You will need to use: "~(*-Architectural,*-Structural)" to exclude both, however, this filter will be stored in the ACLYDICTIONARY Dictionary, not ACAD_LAYERFILTERS Dictionary so different code will be required.

 

6- To define a filter to hide layers matching "*-Architectural" OR show layers matching "3D *", using "~*-Architectural,3D *", the code doesn't work.

 

If I have understood your intention, I don't think this is possible, since this requires AND logic: i.e. exclude '*-Architectural' AND include '3D *'

Posted
For this filter in your drawing you have mispelled 'Architectural' as 'Aechitectural'
:oops:

 

Since each rule in the filter is applied using OR logic, the '-Structural' layers will be permitted by the '~*-Architectural' rule, and similarly the '-Architectural' layers will be permitted by the '~*-Structural' rule, hence both will remain.
:)

 

You will need to use: "~(*-Architectural,*-Structural)" to exclude both, however, this filter will be stored in the ACLYDICTIONARY Dictionary, not ACAD_LAYERFILTERS Dictionary so different code will be required.
:working:

 

If I have understood your intention, I don't think this is possible, since this requires AND logic: i.e. exclude '*-Architectural' AND include '3D *'
:shock:
Posted

You're very welcome Ahankhah, I hope you can learn more about the Dictionary structure from my simple example :)

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...