<?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: Aborting long running ElementIntersectsElementFilter in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8572443#M44501</link>
    <description>&lt;P&gt;If your elements are not already all loaded in memory, the element intersection filter will force them to load. The bounding box filter will not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another question:&amp;nbsp;Do you want to cancel because you found what you were looking for, or because you reached some time limit?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Generally, the evaluation is on demand, using&amp;nbsp;iterators, so as long as you don't try to convert the results to a collection, you can&amp;nbsp;&lt;SPAN class="s1"&gt;write the code to stop whenever you&amp;nbsp; want.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="s1"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Feb 2019 21:10:18 GMT</pubDate>
    <dc:creator>jeremytammik</dc:creator>
    <dc:date>2019-02-04T21:10:18Z</dc:date>
    <item>
      <title>Aborting long running ElementIntersectsElementFilter</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8566911#M44494</link>
      <description>&lt;P&gt;I have really large models where I do some ElementIntersectsElementFilter that can take a long time to process, and sometimes I want to abort them in a graceful way. Is this possible?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I've read about task cancellation tokens, but all the examples I've seen using this approach have been loops where I can check if cancellation has been requested. But the ElementIntersectsElementFilter is out of my control and I can't really see how I can cancel it.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2019 15:35:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8566911#M44494</guid>
      <dc:creator>ottosson_mathias</dc:creator>
      <dc:date>2019-02-01T15:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: Aborting long running ElementIntersectsElementFilter</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8570472#M44495</link>
      <description>&lt;P&gt;Dear Mathias,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for the interesting question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not aware of any way to do this, I'm afraid.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I'm checking wth the development team for you to see what they may come up with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any way you can further optimise the filter beforehand?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can hardly imagine that you have completely exhausted all filtering optimisation possibilities and it is still slow, however large the model is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jeremy&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 07:04:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8570472#M44495</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2019-02-04T07:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: Aborting long running ElementIntersectsElementFilter</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8570625#M44496</link>
      <description>&lt;P&gt;Thank you Jeremy. I would be very interested in any findings from the dev team.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've been thinking in the same line as you but can't really see how I can filter more efficiently at the moment. I thought maybe a bounding box filter would make it quicker, but I suspect, after trying, that the ElementIntersectsElementFilter works somewhat similarly under the hood since I got close to same as before (a bit slower even).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But this is how it looks. I have a loop that I can cancel via a cancellation token. But I'm still interested in a more efficient filter if possible. Do you see anything obvious?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;private List&amp;lt;Element&amp;gt; WallMepClashDetection(Document doc, List&amp;lt;Element&amp;gt; walls)
{
    var filterCategories = new List&amp;lt;BuiltInCategory&amp;gt;
        {
            BuiltInCategory.OST_DuctCurves,
            BuiltInCategory.OST_PipeCurves
        };

    foreach (var wall in walls)
    {
        var clashingElements = new FilteredElementCollector(doc)
            .WhereElementIsNotElementType()
            .WherePasses(new ElementMulticategoryFilter(filterCategories))
            .WherePasses(new ElementIntersectsElementFilter(wall));

        // Do stuff...
    }
}
&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 08:58:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8570625#M44496</guid>
      <dc:creator>ottosson_mathias</dc:creator>
      <dc:date>2019-02-04T08:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: Aborting long running ElementIntersectsElementFilter</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8570692#M44497</link>
      <description>&lt;P&gt;&lt;SPAN&gt;The bounding box filter is a quick filter, whereas the element intersection one is slow.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This can make a huge difference, especially in large models:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="http://thebuildingcoder.typepad.com/blog/2015/12/quick-slow-and-linq-element-filtering.html" target="_blank" rel="noopener"&gt;http://thebuildingcoder.typepad.com/blog/2015/12/quick-slow-and-linq-element-filtering.html&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Can you try this for starters?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;  var cats = new List&amp;lt;BuiltInCategory&amp;gt;
  {
    BuiltInCategory.OST_DuctCurves,
    BuiltInCategory.OST_PipeCurves
  };

  var mepfilter = new ElementMulticategoryFilter( cats );

  BoundingBoxXYZ bb = wall.get_BoundingBox( null );
  Outline o = new Outline( bb.Min, bb.Max );

  var bbfilter = new &lt;SPAN&gt;BoundingBoxIntersectsFilter&lt;/SPAN&gt;( o );

  var clashingElements 
    = new FilteredElementCollector( doc )
      .WhereElementIsNotElementType()
      .WherePasses( mepfilter )
      .WherePasses( bbfilter ); &lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Jeremy&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 09:28:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8570692#M44497</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2019-02-04T09:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: Aborting long running ElementIntersectsElementFilter</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8570795#M44498</link>
      <description>&lt;P&gt;Thanks! That is what I tried, as I stated in my previous response. The result was a slight decrease in performance by a few percent. And for some reason I got fewer collisions as a result which felt a bit odd =S&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 10:23:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8570795#M44498</guid>
      <dc:creator>ottosson_mathias</dc:creator>
      <dc:date>2019-02-04T10:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: Aborting long running ElementIntersectsElementFilter</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8570828#M44499</link>
      <description>&lt;P&gt;Wow! Well, in that case, all your elements have already been completely loaded when the collector is executed. I guess you have a lot of memory. I cannot suggest anything further yet. Let's see what the devteam come up with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 10:46:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8570828#M44499</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2019-02-04T10:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: Aborting long running ElementIntersectsElementFilter</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8571948#M44500</link>
      <description>&lt;P&gt;So you mean that my approach is bad from a memory perspective? I haven't really noticed or measured so I didn't think about it. Should I use the BoundingBoxIntersectsFilter to lower the memory footprint?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 17:45:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8571948#M44500</guid>
      <dc:creator>ottosson_mathias</dc:creator>
      <dc:date>2019-02-04T17:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: Aborting long running ElementIntersectsElementFilter</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8572443#M44501</link>
      <description>&lt;P&gt;If your elements are not already all loaded in memory, the element intersection filter will force them to load. The bounding box filter will not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another question:&amp;nbsp;Do you want to cancel because you found what you were looking for, or because you reached some time limit?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Generally, the evaluation is on demand, using&amp;nbsp;iterators, so as long as you don't try to convert the results to a collection, you can&amp;nbsp;&lt;SPAN class="s1"&gt;write the code to stop whenever you&amp;nbsp; want.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="s1"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 21:10:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8572443#M44501</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2019-02-04T21:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: Aborting long running ElementIntersectsElementFilter</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8573286#M44502</link>
      <description>&lt;P&gt;Oh, that's interesting. I will have to check memory usage when comparing the two cases, just out of curiosity.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I started out I didn't have any means of seeing progress when running heavy intersection filters. And my main motivation was to be able to cancel if the command felt unresponsive or hung. But I've since refactored to use the loop approach which makes it possible to do that and also show a progress bar. I think this applies to any long running command that is out of the control of the developer.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2019 07:44:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8573286#M44502</guid>
      <dc:creator>ottosson_mathias</dc:creator>
      <dc:date>2019-02-05T07:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Aborting long running ElementIntersectsElementFilter</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8573382#M44503</link>
      <description>&lt;P&gt;Yes, please check memory usage.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also understand the concept of iterators.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;  filtered element collector X = ...
  foreach element in X:
    do something to X
    break out of the loop if you wish at any time&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can interrupt your processing of the results returned by the collector at any time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should NOT convert the collector to a list or any other collection.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That would force it to return all the elements, which would cost time if there are many.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Iterating over them one by one does not, costs no time, and can be interrupted any time you like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please confirm that this solves your problem entirely.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jeremy&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2019 08:42:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8573382#M44503</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2019-02-05T08:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: Aborting long running ElementIntersectsElementFilter</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8575286#M44504</link>
      <description>&lt;P&gt;Devteam adds:&amp;nbsp;In one of the samples, they loop over walls and call the same filter for each. So there's an opportunity to stop at each wall before calling it again. But even within the same iteration, it should be possible to break early if it's reached some limit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2019 21:03:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8575286#M44504</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2019-02-05T21:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: Aborting long running ElementIntersectsElementFilter</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8576368#M44505</link>
      <description>&lt;P&gt;Thank you for the information. I use loops now so I will be able to cancel the command as suggested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for taking the time to help, I've learned some things &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Feb 2019 10:23:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8576368#M44505</guid>
      <dc:creator>ottosson_mathias</dc:creator>
      <dc:date>2019-02-06T10:23:57Z</dc:date>
    </item>
    <item>
      <title>Re: Aborting long running ElementIntersectsElementFilter</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8576608#M44506</link>
      <description>&lt;P&gt;Thank you for your confirmation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I edited and published our conversation for posterity:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/2019/02/cancelling-filtered-element-collection.html" target="_blank"&gt;https://thebuildingcoder.typepad.com/blog/2019/02/cancelling-filtered-element-collection.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for raising this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jeremy&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Feb 2019 12:10:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/aborting-long-running-elementintersectselementfilter/m-p/8576608#M44506</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2019-02-06T12:10:21Z</dc:date>
    </item>
  </channel>
</rss>

