Ahankhah Posted September 9, 2012 Posted September 9, 2012 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. Quote
Lee Mac Posted September 9, 2012 Posted September 9, 2012 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]) ) Quote
Ahankhah Posted September 9, 2012 Author Posted September 9, 2012 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? Quote
Lee Mac Posted September 9, 2012 Posted September 9, 2012 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 *". Quote
BIGAL Posted September 10, 2012 Posted September 10, 2012 Its a bit old fashioned but you can use -LA to do the same. -la off 2d* T 3d* on 1d* Quote
Ahankhah Posted September 10, 2012 Author Posted September 10, 2012 (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 September 10, 2012 by Ahankhah Quote
Ahankhah Posted September 10, 2012 Author Posted September 10, 2012 (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 September 10, 2012 by Ahankhah Quote
Lee Mac Posted September 10, 2012 Posted September 10, 2012 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 *' Quote
Ahankhah Posted September 11, 2012 Author Posted September 11, 2012 For this filter in your drawing you have mispelled 'Architectural' as 'Aechitectural' 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. 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 *' Quote
Lee Mac Posted September 11, 2012 Posted September 11, 2012 You're very welcome Ahankhah, I hope you can learn more about the Dictionary structure from my simple example Quote
Recommended Posts
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.