<?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: Loop through sheets - generating graphics in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8721267#M43241</link>
    <description>&lt;P&gt;... and you suppress the annoying regeneration message&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Apr 2019 17:06:07 GMT</pubDate>
    <dc:creator>jeremytammik</dc:creator>
    <dc:date>2019-04-10T17:06:07Z</dc:date>
    <item>
      <title>Loop through sheets - generating graphics</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8713505#M43232</link>
      <description>&lt;P&gt;Hey folks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My program loops through all the sheets in a document (open in the background - no UI) to get some info such as name, number, "approved by" etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why does Revit, during the looping, say "&lt;EM&gt;Generating graphics for Sheet: -nameofsheet-&lt;/EM&gt;" with a loading bar, at the very bottom-left corner of the Revit window? (image below) What is it doing?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 713px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/623499iAB60576DE0F1B787/image-dimensions/713x104?v=v2" width="713" height="104" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems to me like it's more time consuming than simply accessing the sheets in the document (as it does for, for example, model elements, etc.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it possible to avoid this and just get the info I need without "generating graphics"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Andrea&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2019 04:48:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8713505#M43232</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-04-08T04:48:18Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through sheets - generating graphics</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8713532#M43233</link>
      <description>&lt;P&gt;Can you share the code that is looping through the sheets?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2019 05:14:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8713532#M43233</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2019-04-08T05:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through sheets - generating graphics</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8713544#M43234</link>
      <description>&lt;P&gt;Sure! Sorry I didn't put it here straight away!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;// Sheets
foreach (Element sheetElement in CollectSheetElements(currentDoc))
{
    ViewSheet sheet = sheetElement as ViewSheet;

    // Get titleblock
    FilteredElementCollector titleblock =
        new FilteredElementCollector(currentDoc, sheet.Id)
        .OfCategory(BuiltInCategory.OST_TitleBlocks);

    Element titleblockElement = titleblock.First();

    // Get id of titlebloc type
    int? titleblockDbId = GetTypeIdDb(currentDoc, titleblockElement, types);

    RevitSheet revitSheet = new RevitSheet(
        file.FileId,
        sheet.ViewName,
        sheet.SheetNumber,
        GetParameterValueByName(sheetElement, "Approved By"),
        GetParameterValueByName(sheetElement, "Designed By"),
        GetParameterValueByName(sheetElement, "Checked By"),
        GetParameterValueByName(sheetElement, "Drawn By"),
        GetParameterValueByName(sheetElement, "Sheet Issue Date"),
        titleblockDbId);

    // Write sheets
    connection.Execute(DbSqlCommands.sheetsSql, revitSheet, transaction: transaction);
}
&lt;/PRE&gt;
&lt;P&gt;where&amp;nbsp;&lt;STRONG&gt;RevitSheet &lt;/STRONG&gt;is a custom class that I created to write into a db. And there a few other custom method but I don't think they would matter here (but happy to copy them too if they do)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And this is how I collect the sheets:&lt;/P&gt;
&lt;PRE&gt;        internal static List&amp;lt;Element&amp;gt; CollectSheetElements(Document doc)
        {
            FilteredElementCollector views
                = new FilteredElementCollector(doc)
                .OfCategory(BuiltInCategory.OST_Sheets);

            return views.ToElements().ToList();
        }&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Andrea&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2019 05:22:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8713544#M43234</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-04-08T05:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through sheets - generating graphics</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8713569#M43235</link>
      <description>&lt;P&gt;First of all, a small comment on enhancing performance:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can completely eliminate two expensive method calls from&amp;nbsp;CollectSheetElements; both ToElements and ToList serve no purpose whatsoever. Change the return type from List&amp;lt;Element&amp;gt; to IEnumerable&amp;lt;Element&amp;gt; and eliminate those two calls. That will save you time and space, twice over.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately, I have no idea what could be causing the graphics regeneration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll ask the development team about that for 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>Mon, 08 Apr 2019 05:37:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8713569#M43235</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2019-04-08T05:37:31Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through sheets - generating graphics</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8713597#M43236</link>
      <description>&lt;P&gt;Thank you so much for your advice&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/413917"&gt;@jeremytammik&lt;/a&gt;&amp;nbsp;! That's really appreciated!&lt;BR /&gt;&lt;BR /&gt;In regards to the regeneration: Could it be due to the bit of code where I'm taking the titleblock assigned to the sheet?&lt;/P&gt;
&lt;PRE&gt;new FilteredElementCollector(currentDoc, sheet.Id).OfCategory(BuiltInCategory.OST_TitleBlocks);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Where I do this? (it still wouldn't explain the regeneration of the graphics to me...)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for passing my question on to the dev team.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let me know if they can figure out why.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Andrea&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2019 05:58:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8713597#M43236</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-04-08T05:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through sheets - generating graphics</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8713710#M43237</link>
      <description>&lt;P&gt;My initial reaction was 'no'...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, maybe the sheet is indeed regenerated to determine which elements to return for that collector, since the view id is specified... ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I asked the devteam and hope they will be able to reply fast.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2019 07:04:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8713710#M43237</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2019-04-08T07:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through sheets - generating graphics</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8713723#M43238</link>
      <description>&lt;P&gt;That was my same train of thought.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yeah hopefully they will reply soon! That would help a lot as I'm really curious to understand what's going on there now!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let me know.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Andrea&lt;/P&gt;</description>
      <pubDate>Mon, 08 Apr 2019 07:10:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8713723#M43238</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-04-08T07:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through sheets - generating graphics</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8717277#M43239</link>
      <description>They have replied and share a really good idea for an alternative approach which will hopefully solve the problem. The reason is exactly what we thought it was:
 
This is not regeneration, it is generating the view.  In order to iterate elements in the view, it needs to be generated (even if non-visible).    So the FilteredElementCollector(doc, viewId) is causing that.   
 
Trying to think of another option: perhaps you could visit all Titleblock instances in the document, and ask it for its view id, rather than visiting elements in the view?
 
Cheers,
 
Jeremy</description>
      <pubDate>Tue, 09 Apr 2019 12:12:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8717277#M43239</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2019-04-09T12:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through sheets - generating graphics</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8719256#M43240</link>
      <description>&lt;P&gt;Thank you Jeremy for following up!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now that's a great solution and it works great!&lt;BR /&gt;&lt;BR /&gt;If I get all the titleblocks from the document and then take the one with the same OwnerViewId property as the Id of the sheet it doesn't generate the sheet!&lt;/P&gt;
&lt;P&gt;snippet here:&lt;/P&gt;
&lt;PRE&gt;FilteredElementCollector allTitleBlocks = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_TitleBlocks);

foreach (Element sheetElement in CollectSheetElements(currentDoc))
{
    // Get sheet's titleblock
    Element titleblock = allTitleblocks.Where(t =&amp;gt; t.OwnerViewId == sheet.Id).First();
}&lt;/PRE&gt;
&lt;P&gt;Unfortunately that doesn't speed up the process as much as I thought, weirdly enough. The script was taking 6.77 minutes with the old method and takes now 6.32 minutes now.&lt;/P&gt;
&lt;P&gt;Although, it needs to be considered that the program doesn't only taking into account the sheets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Andrea&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 02:33:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8719256#M43240</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-04-10T02:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through sheets - generating graphics</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8721267#M43241</link>
      <description>&lt;P&gt;... and you suppress the annoying regeneration message&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 17:06:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8721267#M43241</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2019-04-10T17:06:07Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through sheets - generating graphics</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8721293#M43242</link>
      <description>&lt;P&gt;You could improve this by implementing a dictionary inverting the relationship:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;  FilteredElementCollector allTitleBlocks 
    = new FilteredElementCollector(doc)
      .OfCategory(BuiltInCategory.OST_TitleBlocks);

  // Map sheet to title block:

  Dictionary&amp;lt;ElementId, ElementId&amp;gt; map_sheet_to_title_block ...

  for each title block t in allTitleBlocks:
    map_sheet_to_title_block.Add( t.OwnerId, t.Id )&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After that, use&amp;nbsp;map_sheet_to_title_block(sheet.Id, t.Id) to get the title block.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No more need for a call to Where in each loop iteration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 17:13:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8721293#M43242</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2019-04-10T17:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through sheets - generating graphics</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8722217#M43243</link>
      <description>&lt;P&gt;Yeah that's actually a great idea!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for all the advice&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/413917"&gt;@jeremytammik&lt;/a&gt;&amp;nbsp;!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll use this same strategy for when I extract the parameters too! Should make it better too!&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2019 01:15:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8722217#M43243</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-04-11T01:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through sheets - generating graphics</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8722450#M43244</link>
      <description>&lt;P&gt;My pleasure entirely.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Seven minutes is a long time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should definitely benchmark your entire add-in to discover what is taking so much time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It could be built-in Revit operations. However, with obvious optimisation possibilities like that, you may be able to speed it up a lot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck!&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>Thu, 11 Apr 2019 05:16:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8722450#M43244</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2019-04-11T05:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: Loop through sheets - generating graphics</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8725216#M43245</link>
      <description>&lt;P&gt;Yes, I actually benchmarked the process and the thing that takes 80% of the processing time (5 min of the total 6 and a bit) is extracting all the instance parameters of the model elements...I guess it makes sense, a few thousands elements with 20/30 parameters each makes it a lot of parameters &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll probably write another question here on the forum at some point to see if anyone sees a faster way to do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Andrea&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 00:00:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/loop-through-sheets-generating-graphics/m-p/8725216#M43245</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-04-12T00:00:51Z</dc:date>
    </item>
  </channel>
</rss>

