Author Topic: SelectionFilter from Object Typ+Layer  (Read 5925 times)

0 Members and 1 Guest are viewing this topic.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
SelectionFilter from Object Typ+Layer
« on: November 12, 2015, 04:06:22 AM »
Hello friends!
I have a question to class SelectionFilter. I want filter diffrent kind of objects on a same layer. In my example I try to filter only 3d-Polylines on Layer "200"
But I get all objects on Layer "200". I suspect that I donīt use right type in
Code: [Select]
new TypedValue((int)DxfCode.Subclass, "AcDb3dPolyline")

Here is the hole code
Code: [Select]
        [CommandMethod("FilterSelectionSet")]
        public static void FilterSelectionSet()
        {
            // Get the current document editor
            Editor acDocEd = Application.DocumentManager.MdiActiveDocument.Editor;

            // Create a TypedValue array to define the filter criteria
           

            TypedValue[] acTypValAr = new TypedValue[3]
            {
                    new TypedValue((int)DxfCode.Subclass, "AcDb3dPolyline"),
                    new TypedValue((int)DxfCode.LayerName, "200"),
                    new TypedValue((int)DxfCode.LayoutName, "Model"),
            };

            // Assign the filter criteria to a SelectionFilter object
            Autodesk.AutoCAD.EditorInput.SelectionFilter acSelFtr = new Autodesk.AutoCAD.EditorInput.SelectionFilter(acTypValAr);

            // Request for objects to be selected in the drawing area
            PromptSelectionResult acSSPrompt;
            acSSPrompt = acDocEd.GetSelection(acSelFtr);

            // If the prompt status is OK, objects were selected
            if (acSSPrompt.Status == PromptStatus.OK)
            {
                SelectionSet acSSet = acSSPrompt.Value;

                Application.ShowAlertDialog("Number of objects selected: " +
                                            acSSet.Count.ToString());
            }
            else
            {
                Application.ShowAlertDialog("Number of objects selected: 0");
            }
        }


gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: SelectionFilter from Object Typ+Layer
« Reply #1 on: November 12, 2015, 06:55:24 AM »
Hi,

You cannot use the DxfCode.SubClass (100) as filter, use the 'DXF type' DxfCode.Start (0) instead.
With DXF, Polyline3d is a POLYLINE as well as Polyline2d and polygon meshes ; so you have to check the 70 flag too (it have to contain the 8 bit code).

Code - C#: [Select]
  1. TypedValue[] acTypValAr = new TypedValue[5]
  2. {
  3.     new TypedValue(0, "POLYLINE"), // DxfCode.Start
  4.     new TypedValue(-4, "&"), // Dxfcode.Operator
  5.     new TypedValue(70, 8), // DxfCode.Int16
  6.     new TypedValue(8, "200"), // DxfCode.LayerName
  7.     new TypedValue(410, "Model"), // DxfCode.LayoutName
  8. };

EDIT: If you're comming from LISP, as suggested in your signature, you can see that the TypedValue array used to build a SelectionFilter instance looks like the list of dotted pairs used in AutoLISP.
« Last Edit: November 12, 2015, 07:15:24 AM by gile »
Speaking English as a French Frog

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: SelectionFilter from Object Typ+Layer
« Reply #2 on: November 12, 2015, 08:27:51 AM »
Hi gile!
Thanks for reply, my problem with your version is that all Polylines whatever "AcDb2dPolyline", "AcDb3dPolyline", "AcDbPolyline" (LWPolyline) comes in one selectionset or?
I would like "AcDb2dPolyline" and "AcDbPolyline" (all 2dPolylines) in one selection
and all "AcDb3dPolyline" in annother selection, is this possible ?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: SelectionFilter from Object Typ+Layer
« Reply #3 on: November 12, 2015, 10:53:58 AM »
Hi gile!
Thanks for reply, my problem with your version is < ... >

Dirk, I'll point out something I come across frequently.
The Problem isn't with gile's code solution ... he addresses your stated issues wonderfully.
The problem is that you asked one question and also expect we know you also want an answer to something not alluded to.

please excuse me if this seems terse and badgering.

I only post this because gile is too polite and amenable to make waves.
« Last Edit: November 12, 2015, 10:57:08 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: SelectionFilter from Object Typ+Layer
« Reply #4 on: November 12, 2015, 02:48:40 PM »
Sorry Kerry, youīre right. It soundīs pretty bad if I get solution, but donīt explain my problem right from beginning. So Iīll do it better. I would ask if you can seperate LWPolyline, 2dPolyline and 3dPolyline (I mean in three selectionsets). In my program it should be possible to can select for example all 2dPolylines on Layer "200" annother try to get all 3dPolyline on Layer "200" and last try get all LWPolyline on Layer "200".

new TypedValue((int)DxfCode.Start,"LWPOLYLINE,POLYLINE") I get all Polylines. In type POLYLINE include 2dPolyline and 3dPolyline, but Iīll have in diffrent selectionsets. That mean 2dPolyline+LwPolyline in one Selection or/and 3dPolyline in annother selection.
Hopefully itīs better to understand now.
?!

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: SelectionFilter from Object Typ+Layer
« Reply #5 on: November 12, 2015, 02:52:44 PM »
Kerry,

Thanks for your reply.
I'm not "too polite", I just have some difficulties with English language.

Dirk,

The example I posted DOES filter only polylines 3d on layer "200" in model space.
I suggest you learn DXF codes (almost the ENTITIES part), selection sets filter lists and the related topics as relational tests and logical grouping tests.
I suggest you learn this using LISP because it's much easier to make tests with AutoCAD and, as I said upper, it's very easy to convert LISP filter lists into .NET TypedValue arrays.
Speaking English as a French Frog

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: SelectionFilter from Object Typ+Layer
« Reply #6 on: November 13, 2015, 02:51:44 AM »
thanx Gile
Iīm not sure with group-code 70. I donīt get select 2d-Polylines
Code: [Select]
            //Filter 3dPolylines
            TypedValue[] acTypValAr = new TypedValue[5]
            {
                new TypedValue(0, "POLYLINE"), // DxfCode.Start
                new TypedValue(-4, "&"), // Dxfcode.Operator
                new TypedValue(70, 8), // DxfCode.Int16
                new TypedValue(8, "200"), // DxfCode.LayerName
                new TypedValue(410, "Model"), // DxfCode.LayoutName
            };
            //Filter 2dPolylines
            TypedValue[] acTypValAr = new TypedValue[5]
            {
                new TypedValue(0, "POLYLINE"), // DxfCode.Start
                new TypedValue(-4, "&"), // Dxfcode.Operator
                new TypedValue(70, 0), // DxfCode.Int16
                new TypedValue(8, "200"), // DxfCode.LayerName
                new TypedValue(410, "Model"), // DxfCode.LayoutName
            };
            //Filter LWPolyline
            TypedValue[] acTypValAr = new TypedValue[5]
            {
                new TypedValue(0, "LWPOLYLINE"), // DxfCode.Start
                new TypedValue(-4, "&"), // Dxfcode.Operator
                new TypedValue(70, 128), // DxfCode.Int16
                new TypedValue(8, "200"), // DxfCode.LayerName
                new TypedValue(410, "Model"), // DxfCode.LayoutName
            };


gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: SelectionFilter from Object Typ+Layer
« Reply #7 on: November 13, 2015, 03:54:52 AM »
From the help about relational tests:
Quote
The bitwise AND, "&", is true if ((integer_group & filter) /= 0)—that is, if any of the bits set in the mask are also set in the integer group.

From the DXF doc for POLYLINE entity70 code :
Quote
   Polyline flag (bit-coded; default = 0):
1 = This is a closed polyline (or a polygon mesh closed in the M direction)
2 = Curve-fit vertices have been added
4 = Spline-fit vertices have been added
8 = This is a 3D polyline
16 = This is a 3D polygon mesh
32 = The polygon mesh is closed in the N direction
64 = The polyline is a polyface mesh
128 = The linetype pattern is generated continuously around the vertices of this polyline

That means a polyline 3d will always have bit 8 and possibly bit 1 (8 + 1 = 9) if closed (and 2 or 4 if splined), so checking for 8 is enough to insure the POLYLINE is a Polyline 3d. 8 & 8 = 8 or 8 & 9 = 8 or 8 & 10 = 8, and so on, all are different from 0.

A polyline 2d may have the bit 0, 2 or 4, plus possibly 1 (if closed), plus possibly 128, i.e. it can be 0, 1, 2, 3 (2 + 1), 4, 5 (4 + 1), 128, 129 (1 + 128), 130 (2 + 128), 131 (1 + 2 + 128), 132 (4 + 128), 133 (1 + 4 + 128). But it cannot have bit 8, 16, 32 nor 64. So checking if the POLYLINE entity do not have any of these bits is enough to insure it's a Polyline 2d.
So you can filter Polyline 2d using a logical group "NOT" with the relational test "&" and 120 (8 + 16 +32 +64).

Here're some LISP expressions which only focus on the entity type to filter Polyline, Polyline2d and Polyline3d.

Polyline: LWPOLYLINE is enough
Code - Auto/Visual Lisp: [Select]
  1. (sssetfirst nil (ssget "_X" '((0 . "LWPOLYLINE"))))

Polyline3d: POLYLINE and bit 8
Code - Auto/Visual Lisp: [Select]
  1. (sssetfirst nil (ssget "_X" '((0 . "POLYLINE") (-4 . "&") (70 . 8))))

Polyline2d: POLYLINE and not bit 8 or 16 or 32 or 64
Code - Auto/Visual Lisp: [Select]
  1. (sssetfirst nil (ssget "_X" '((0 . "POLYLINE") (-4 . "<NOT") (-4 . "&") (70 . 120) (-4 . "NOT>"))))

I let you add other filtering criterias (layer, layout)...
« Last Edit: November 13, 2015, 04:50:25 AM by gile »
Speaking English as a French Frog

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: SelectionFilter from Object Typ+Layer
« Reply #8 on: November 13, 2015, 05:15:08 AM »
Thank you so much for your time and your solution. That helps a lot and saved time. Iīm happy!