<?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 Re: Issue in filter selection in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/issue-in-filter-selection/m-p/9843925#M18083</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this way:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;var filter = new SelectionFilter(new[]
{
    new TypedValue(2, "note"),
    new TypedValue(410, LayoutManager.Current.CurrentLayout)
});&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 03 Nov 2020 22:24:45 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2020-11-03T22:24:45Z</dc:date>
    <item>
      <title>Issue in filter selection</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-in-filter-selection/m-p/9843799#M18082</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I have below codes. But it has error(image attached).&lt;/P&gt;&lt;P&gt;If i omit the line 'filterlist[1] = new TypedValue(67, s);' it works.&lt;/P&gt;&lt;P&gt;What is the issue?&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;&lt;BR /&gt;LayoutManager layoutMgr = LayoutManager.Current;&lt;BR /&gt;string s = layoutMgr.CurrentLayout;&lt;BR /&gt;TypedValue[] filterlist = new TypedValue[2];&lt;BR /&gt;filterlist[0] = new TypedValue(2, "note");&lt;BR /&gt;filterlist[1] = new TypedValue(67, s);&lt;BR /&gt;Autodesk.AutoCAD.EditorInput.SelectionFilter filter = new Autodesk.AutoCAD.EditorInput.SelectionFilter(filterlist);&lt;BR /&gt;PromptSelectionResult Promptentity = editor.SelectAll(filter);&lt;BR /&gt;SelectionSet sval = Promptentity.Value; &lt;/P&gt;</description>
      <pubDate>Tue, 03 Nov 2020 21:37:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-in-filter-selection/m-p/9843799#M18082</guid>
      <dc:creator>mehdi-guida</dc:creator>
      <dc:date>2020-11-03T21:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: Issue in filter selection</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-in-filter-selection/m-p/9843925#M18083</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this way:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;var filter = new SelectionFilter(new[]
{
    new TypedValue(2, "note"),
    new TypedValue(410, LayoutManager.Current.CurrentLayout)
});&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 03 Nov 2020 22:24:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-in-filter-selection/m-p/9843925#M18083</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-11-03T22:24:45Z</dc:date>
    </item>
    <item>
      <title>Re: Issue in filter selection</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-in-filter-selection/m-p/9844096#M18084</link>
      <description>&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;But it works only for simple blocks.&lt;/P&gt;&lt;P&gt;if the blocks are dynamic , it can't select them.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 00:29:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-in-filter-selection/m-p/9844096#M18084</guid>
      <dc:creator>mehdi-guida</dc:creator>
      <dc:date>2020-11-04T00:29:38Z</dc:date>
    </item>
    <item>
      <title>Re: Issue in filter selection</title>
      <link>https://forums.autodesk.com/t5/net-forum/issue-in-filter-selection/m-p/9844515#M18085</link>
      <description>&lt;P&gt;You cannot directly filter dynamic blocs by name wit a selection filter. You have to check the Name of the DynamicBlockTableRecord of each block reference.&lt;/P&gt;
&lt;P&gt;Assuming you want to get all blocks by name in the current layout BlockTableRecord, the simplest (and faster) way is to iterate through all entities in the current space.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;using (var tr = db.TransactionManager.StartTransaction())
{
    var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
    foreach (ObjectId id in curSpace)
    {
        if (id.ObjectClass.DxfName == "INSERT")
        {
            var br = (BlockReference)tr.GetObject(id, OpenMode.ForRead);
            var btr = (BlockTableRecord)tr.GetObject(br.DynamicBlockTableRecord, OpenMode.ForRead);
            if (btr.Name == "note")
            {
                // do your stuff with the block reference
            }
        }
    }
    tr.Commit();
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another example with a separate method using Linq&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;static IEnumerable&amp;lt;ObjectId&amp;gt; GetAllCurrentSpaceBlocksByName(string blockName)
{
    var db = HostApplicationServices.WorkingDatabase;
    using (var tr = db.TransactionManager.StartOpenCloseTransaction())
    {
        var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
        return curSpace
            .Cast&amp;lt;ObjectId&amp;gt;()
            .Where(id =&amp;gt; id.ObjectClass.DxfName == "INSERT")
            .Select(id =&amp;gt; (BlockReference)tr.GetObject(id, OpenMode.ForRead))
            .Where(br =&amp;gt; ((BlockTableRecord)tr.GetObject(br.DynamicBlockTableRecord, OpenMode.ForRead)).Name == blockName)
            .Select(br =&amp;gt; br.ObjectId);
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 04 Nov 2020 06:33:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/issue-in-filter-selection/m-p/9844515#M18085</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2020-11-04T06:33:14Z</dc:date>
    </item>
  </channel>
</rss>

