<?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: FilteredElementCollector only works sporadically when collecting ViewSheet in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/filteredelementcollector-only-works-sporadically-when-collecting/m-p/7845909#M51786</link>
    <description>&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did think it was something like that, but it still failed even when that was the entirety of an ExternalCommand Execute method.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After a bit more headscratching, I eventually tracked down the culprit to a bit of UI code that had been introduced that defined a custom AssemblyResolve function - removing that seems to have everything working consistently - I can only assume it was causing Revit to fail to resolve one of its own assemblies under certain circumstances&lt;/P&gt;</description>
    <pubDate>Mon, 12 Mar 2018 13:20:41 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-03-12T13:20:41Z</dc:date>
    <item>
      <title>FilteredElementCollector only works sporadically when collecting ViewSheet</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/filteredelementcollector-only-works-sporadically-when-collecting/m-p/7845429#M51782</link>
      <description>&lt;P&gt;I have a plugin that contains the following code snippet&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;var document = commandData.Application.ActiveUIDocument.Document;&lt;BR /&gt;var collector = new FilteredElementCollector(document);
var views = collector.OfClass(typeof(ViewSheet)).ToElements().Cast&amp;lt;ViewSheet&amp;gt;();&lt;/PRE&gt;&lt;P&gt;Testing against the&amp;nbsp;&lt;EM&gt;rac_basic_sample_revit&amp;nbsp;&lt;/EM&gt;project that comes supplied with Revit 2018.2, I sometimes get six valid ViewSheets returned, as expected, and other times I just get six nulls.&amp;nbsp; I get similar unpredictable results querying other types.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anybody shed any light on to what I may be doing wrongly?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2018 10:47:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/filteredelementcollector-only-works-sporadically-when-collecting/m-p/7845429#M51782</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-12T10:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: FilteredElementCollector only works sporadically when collecting ViewSheet</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/filteredelementcollector-only-works-sporadically-when-collecting/m-p/7845490#M51783</link>
      <description>&lt;P&gt;Nope.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Never heard of such a problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The filtered element collectors seem to be completely reliable in all cases, as far as I can tell.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, you can eliminate the call to `ToElements`, it does absolutely nothing except waste time and effort.&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;</description>
      <pubDate>Mon, 12 Mar 2018 11:11:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/filteredelementcollector-only-works-sporadically-when-collecting/m-p/7845490#M51783</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2018-03-12T11:11:14Z</dc:date>
    </item>
    <item>
      <title>Re: FilteredElementCollector only works sporadically when collecting ViewSheet</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/filteredelementcollector-only-works-sporadically-when-collecting/m-p/7845516#M51784</link>
      <description>&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried refactoring the code as so:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;var collector = new FilteredElementCollector(document);

var views = collector.OfClass(typeof(ViewSheet));

foreach (var element in views)
{
    var view = element as ViewSheet;
    ...
}           &lt;/PRE&gt;&lt;P&gt;But iterating the views result gives an immediate exception:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Autodesk.Revit.Exceptions.InternalException
  HResult=0x80131500
  Message=A managed exception was thrown by Revit or by one of its external applications.
  Source=RevitAPI
  StackTrace:
   at Autodesk.Revit.DB.FilteredElementCollector.GetFilteredElementCollectorIterator()
   at Autodesk.Revit.DB.DocumentExtensions.GetViewSheets(Document _document) &lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Mar 2018 11:26:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/filteredelementcollector-only-works-sporadically-when-collecting/m-p/7845516#M51784</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-12T11:26:30Z</dc:date>
    </item>
    <item>
      <title>Re: FilteredElementCollector only works sporadically when collecting ViewSheet</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/filteredelementcollector-only-works-sporadically-when-collecting/m-p/7845650#M51785</link>
      <description>&lt;P&gt;Your code is presumably running outside a valid Revit API&amp;nbsp;context:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://thebuildingcoder.typepad.com/blog/2015/12/external-event-and-10-year-forum-anniversary.html#2" target="_blank"&gt;http://thebuildingcoder.typepad.com/blog/2015/12/external-event-and-10-year-forum-anniversary.html#2&lt;/A&gt;&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;</description>
      <pubDate>Mon, 12 Mar 2018 12:15:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/filteredelementcollector-only-works-sporadically-when-collecting/m-p/7845650#M51785</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2018-03-12T12:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: FilteredElementCollector only works sporadically when collecting ViewSheet</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/filteredelementcollector-only-works-sporadically-when-collecting/m-p/7845909#M51786</link>
      <description>&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did think it was something like that, but it still failed even when that was the entirety of an ExternalCommand Execute method.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After a bit more headscratching, I eventually tracked down the culprit to a bit of UI code that had been introduced that defined a custom AssemblyResolve function - removing that seems to have everything working consistently - I can only assume it was causing Revit to fail to resolve one of its own assemblies under certain circumstances&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2018 13:20:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/filteredelementcollector-only-works-sporadically-when-collecting/m-p/7845909#M51786</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-12T13:20:41Z</dc:date>
    </item>
  </channel>
</rss>

