<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to apply a selection filter on a ObjectIDCollection? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-to-apply-a-selection-filter-on-a-objectidcollection/m-p/3733194#M52074</link>
    <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I wonder if its possible to apply a filter to a subset of entities (that could be the result of a previous filtering).&lt;/P&gt;</description>
    <pubDate>Wed, 12 Dec 2012 06:56:34 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2012-12-12T06:56:34Z</dc:date>
    <item>
      <title>How to apply a selection filter on a ObjectIDCollection?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-apply-a-selection-filter-on-a-objectidcollection/m-p/3733194#M52074</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I wonder if its possible to apply a filter to a subset of entities (that could be the result of a previous filtering).&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2012 06:56:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-apply-a-selection-filter-on-a-objectidcollection/m-p/3733194#M52074</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-12-12T06:56:34Z</dc:date>
    </item>
    <item>
      <title>Re : How to apply a selection filter on a ObjectIDCollection?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-apply-a-selection-filter-on-a-objectidcollection/m-p/3733222#M52075</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By my side, i think Linq provides many useful extension methods to deal with all types of collection, those which do not implement IEnumerable&amp;lt;T&amp;gt; as ObjectIdcollection may be converted to IEnumerable&amp;lt;ObjectId&amp;gt; with Cast&amp;lt;ObjectId&amp;gt;&amp;gt;().&lt;/P&gt;&lt;P&gt;Look at the Linq extension methods here:&lt;/P&gt;&lt;P&gt;&lt;A target="_blank" href="http://msdn.microsoft.com/en-us/library/9eekhta0.aspx"&gt;http://msdn.microsoft.com/en-us/library/9eekhta0.aspx&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To filter a collection the Where extension methode is quite easy to use passing it a function (delegate) returning true for the elements you want to keep in the collection.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example filtering the Line entities in an ObjectIdCollection (called ids):&lt;/P&gt;&lt;PRE&gt;ids.cast&amp;lt;ObectId&amp;gt;()
    .Where(id =&amp;gt; id.ObjectClass.DxfName == "LINE")&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2012 07:43:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-apply-a-selection-filter-on-a-objectidcollection/m-p/3733222#M52075</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2012-12-12T07:43:03Z</dc:date>
    </item>
    <item>
      <title>Re : How to apply a selection filter on a ObjectIDCollection?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-apply-a-selection-filter-on-a-objectidcollection/m-p/3733240#M52076</link>
      <description>&lt;P&gt;Hi Gilles,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I like your Linq approach, but the filtering criterias I need aren't provided by id.ObjectClass&lt;/P&gt;&lt;P&gt;I want to filter for XData, Layer and others.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2012 08:09:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-apply-a-selection-filter-on-a-objectidcollection/m-p/3733240#M52076</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-12-12T08:09:20Z</dc:date>
    </item>
    <item>
      <title>Re : How to apply a selection filter on a ObjectIDCollection?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-apply-a-selection-filter-on-a-objectidcollection/m-p/3733588#M52077</link>
      <description>&lt;P&gt;It was just an example, for xdata, layer, you'll need to Open the objects. This can be done mapping the ObjectIdCollection to Entities with the Select() method, then adapting the Where() argument function as you need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;another example to be used within a Transaction (tr):&lt;/P&gt;&lt;PRE&gt;ids.Cast&amp;lt;ObjectId&amp;gt;()
    .Select(id =&amp;gt; (Entity)tr.GetObject(id, OpenMode.ForRead))
    .Where(ent =&amp;gt; ent.Layer == layerName)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2012 13:38:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-apply-a-selection-filter-on-a-objectidcollection/m-p/3733588#M52077</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2012-12-12T13:38:00Z</dc:date>
    </item>
    <item>
      <title>Re : How to apply a selection filter on a ObjectIDCollection?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-apply-a-selection-filter-on-a-objectidcollection/m-p/3735262#M52078</link>
      <description>&lt;P&gt;Initially I tried to work with SelectionFilter (TypedValues) only and select the entities via editor.selectAll(SelectionFilter), since its performance is great. But there are some limits, e.g. I can't filter for entities with certain XData.&lt;/P&gt;&lt;P&gt;So I switched to work with Predicates (&lt;SPAN style="color: #a65300;"&gt;Expression&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="color: #a65300;"&gt;Func&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="color: #a65300;"&gt;Entity&lt;/SPAN&gt;,&amp;nbsp;&lt;SPAN style="color: #a65300;"&gt;Boolean&lt;/SPAN&gt;&amp;gt;&amp;gt;) that also can be combined via PredicateBuilder. The mapping from ObjectIDCollection to Entities is as you suggested:&lt;/P&gt;&lt;PRE&gt;IEnumerable&amp;lt;Entity&amp;gt; ents = objIds.Select(id =&amp;gt; tr.GetObject(id, OpenMode.ForRead)).Cast&amp;lt;Entity&amp;gt;();&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;The predicate is applied afterwards:&lt;/P&gt;&lt;PRE&gt;IEnumerable&amp;lt;Entity&amp;gt; appliedEnts = ents.AsQueryable().Where(predicate);&lt;/PRE&gt;&lt;P&gt;This solution provides for me the most flexibility with only a little lack of performance, since I only need to open one Transaction.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2012 11:08:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-apply-a-selection-filter-on-a-objectidcollection/m-p/3735262#M52078</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-12-13T11:08:06Z</dc:date>
    </item>
    <item>
      <title>Re : How to apply a selection filter on a ObjectIDCollection?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-apply-a-selection-filter-on-a-objectidcollection/m-p/3736928#M52079</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;&lt;P&gt;Initially I tried to work with SelectionFilter (TypedValues) only and select the entities via editor.selectAll(SelectionFilter), since its performance is great. But there are some limits, e.g. I can't filter for entities with certain XData.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;You can filter on the XData application name to reduce the selection to only entities having one or more application names, and with that, reduce the number of entities that you must open to examine for more specific criteria, and that's probably a faster solution than having to open all objects selected. Remember that the user can type 'All' to select everything and that means in a large drawing, you will have to open every single object in the current space.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2012 05:23:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-apply-a-selection-filter-on-a-objectidcollection/m-p/3736928#M52079</guid>
      <dc:creator>DiningPhilosopher</dc:creator>
      <dc:date>2012-12-14T05:23:54Z</dc:date>
    </item>
    <item>
      <title>Re : How to apply a selection filter on a ObjectIDCollection?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-apply-a-selection-filter-on-a-objectidcollection/m-p/3737039#M52080</link>
      <description>&lt;P&gt;I benchmarked this with a large drawing ~ 20.000 entities. The performance loss is not really worth mention it.&lt;/P&gt;&lt;P&gt;~0.07 sec vs ~ 0.17 sec.&lt;/P&gt;&lt;P&gt;For that I can not only filter for XData Regappnames but for other XData formats too.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2012 08:59:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-apply-a-selection-filter-on-a-objectidcollection/m-p/3737039#M52080</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-12-14T08:59:16Z</dc:date>
    </item>
    <item>
      <title>Re : How to apply a selection filter on a ObjectIDCollection?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-apply-a-selection-filter-on-a-objectidcollection/m-p/3737485#M52081</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another way is to use the Editor.SelectionAdded event. You can call the Editor.SelectAll() method from a Transaction and combinate classical SelectionFilter with SelectionAdded event filtering.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a little example (I 'm more comfortable giving example than trying to explain in English) where entities are classicaly filtered with layer and registered application and a SelectionAdded event handler is used to filter on the first xdata value: (1001, 'foo")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        [CommandMethod("Test", CommandFlags.Modal)]
        public void Test()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            try
            {
                SelectionFilter filter =
                    new SelectionFilter(new TypedValue[] { new TypedValue(8, "Layer1"), new TypedValue(1001, "RegApp") });
                ed.SelectionAdded += OnSelectionAdded;
                PromptSelectionResult psr = ed.SelectAll(filter);
                if (psr.Status != PromptStatus.OK)
                    return;
                ed.WriteMessage("\n{0} entities selected", psr.Value.Count);
            }
            finally
            {
                ed.SelectionAdded -= OnSelectionAdded;
            }
        }

        void OnSelectionAdded(object sender, SelectionAddedEventArgs e)
        {
            ObjectId[] ids = e.AddedObjects.GetObjectIds();
            for (int i = 0; i &amp;lt; ids.Length; i++)
            {
                using (Entity ent = (Entity)ids[i].Open(OpenMode.ForRead))
                {
                    ResultBuffer xdata = ent.GetXDataForApplication("RegApp");
                    TypedValue[] tvs = xdata.AsArray();
                    if (tvs[0].TypeCode != 1000 || tvs[0].Value != "foo")
                    {
                        e.Remove(i);
                    }
                }
            }
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2012 19:50:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-apply-a-selection-filter-on-a-objectidcollection/m-p/3737485#M52081</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2012-12-14T19:50:28Z</dc:date>
    </item>
    <item>
      <title>Re : How to apply a selection filter on a ObjectIDCollection?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-to-apply-a-selection-filter-on-a-objectidcollection/m-p/3737493#M52082</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;&lt;P&gt;I benchmarked this with a large drawing ~ 20.000 entities. The performance loss is not really worth mention it.&lt;/P&gt;&lt;P&gt;~0.07 sec vs ~ 0.17 sec.&lt;/P&gt;&lt;P&gt;For that I can not only filter for XData Regappnames but for other XData formats too.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Using LINQ against the result of SelectionSet.GetObjectIds() is essentially the same process as using it against all objects in a BlockTableRecord, so I usually pre-filter with a selection set/selection filter first and then use LINQ against the resulting ObjectIds to filter for more specific criteria.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've used that approach with drawings containing betwen 250,000 and 500,000 objects with great sucess and there &amp;nbsp;was a perceptible difference between that and directly filtering the BlockTableRecord. &amp;nbsp;Of course, if you don't deal with drawings that large, it may not matter.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2012 19:57:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-to-apply-a-selection-filter-on-a-objectidcollection/m-p/3737493#M52082</guid>
      <dc:creator>DiningPhilosopher</dc:creator>
      <dc:date>2012-12-14T19:57:46Z</dc:date>
    </item>
  </channel>
</rss>

