<?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: Update Revit errors in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/update-revit-errors/m-p/5266849#M75791</link>
    <description>&lt;P&gt;It looks like you have some confusion regarding the different types of document objects and the namespace of certain classes.&lt;/P&gt;&lt;P&gt;I'll run quickly through the issues I can see in order and then provide a working example below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't see the &lt;STRONG&gt;application&lt;/STRONG&gt;&amp;nbsp;object being declared or passed into your method, is it declared in the class itself? What is its type? It doesn't look to be a standard API class so I'm assuming it's a custom container / helper class. To get at the Database level document&amp;nbsp;you need to dive into the &lt;STRONG&gt;commandData&lt;/STRONG&gt; parameter that is passed into the method by the API. &lt;STRONG&gt;commandData.Application.ActiveUIDocument.Document&lt;/STRONG&gt; is what you need for that, but as I note&amp;nbsp;in my next point I don't think this is actually what you wanted to do.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The &lt;STRONG&gt;rvtDoc&lt;/STRONG&gt; object&amp;nbsp;looks to be of the wrong class for what you are trying to do with it. The UI level document class&amp;nbsp;is the one that contains the &lt;STRONG&gt;Selection&lt;/STRONG&gt; property, you are trying to use the DB level document.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ElementSet&lt;/STRONG&gt; is found in the &lt;STRONG&gt;Autodesk.Revit.DB&lt;/STRONG&gt; namespace, not Revit. You already have the DB namespace declared so ElementSet alone will suffice.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As above, &lt;STRONG&gt;Element&lt;/STRONG&gt; is also a member of the&amp;nbsp;&lt;SPAN&gt;&lt;STRONG&gt;Autodesk.Revit.DB&lt;/STRONG&gt; namespace, you already have this declared, so Element is just fine&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are defining &lt;STRONG&gt;selSet&lt;/STRONG&gt; twice in the same context, the second declaration and assignment looks to be unintentional and not needed, remove it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Selection.Elements&lt;/STRONG&gt; has been depreciated in the 2015 API, it will still work, but you'll need to revisit any code that uses it in a future release as it will no doubt be removed at some point. Best to use &lt;STRONG&gt;Selection.GetElementIds()&lt;/STRONG&gt; instead and then use the ids to query the database Document for the actual Elements. For simplicity, I'll leave this alone in my example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am assuming that the using directives are at the top your file and you have just pasted them below for readability, if not, move them to the top of the source file, outside of the class declaration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As promised here's one that will work better.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Public Result Execute(ExternalCommandData commandData,ref string message,ElementSet elements)
{
UIDocument rvtDoc = commandData.Application.ActiveUIDocument;
ElementSet selSet = rvtDoc.Selection.Elements;
Element elem = default(Element);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While this will fix the code snippet you pasted, if further down the method you are dealing with rvtDoc as if it was a database document, you will get a new set of errors. If this happens just add &lt;STRONG&gt;Document dbDoc =&amp;nbsp;&lt;/STRONG&gt;&lt;SPAN&gt;&lt;STRONG&gt;commandData.Application.ActiveUIDocument.Document;&lt;/STRONG&gt; at the top of the method and update the affected code to suit.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 11 Sep 2014 04:49:55 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2014-09-11T04:49:55Z</dc:date>
    <item>
      <title>Update Revit errors</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/update-revit-errors/m-p/5266599#M75790</link>
      <description>&lt;P&gt;The red text are the errors. Using Revit 2015 and C# 2012 had this running with earlier External Tools trying to update.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Public Result Execute(ExternalCommandData commandData,ref string message,ElementSet elements)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;Document rvtDoc = &lt;SPAN style="color: #ff0000;"&gt;application.&lt;/SPAN&gt;ActiveDocument;&lt;/P&gt;&lt;P&gt;Revit.&lt;SPAN style="color: #ff0000;"&gt;ElementSet&lt;/SPAN&gt; selSet = rvtDoc.&lt;SPAN style="color: #ff0000;"&gt;Selection&lt;/SPAN&gt;.Elements;&lt;/P&gt;&lt;P&gt;Revit.&lt;SPAN style="color: #ff0000;"&gt;Element&lt;/SPAN&gt; elem = default(Revit.&lt;SPAN style="color: #ff0000;"&gt;Element&lt;/SPAN&gt;);&lt;/P&gt;&lt;P&gt;Revit.&lt;SPAN style="color: #ff0000;"&gt;ElementSet selSet&lt;/SPAN&gt; = rvtDoc.&lt;SPAN style="color: #ff0000;"&gt;Selection&lt;/SPAN&gt;.Elements;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;using System; using System.Collections.Generic;&lt;/P&gt;&lt;P&gt;using System.Diagnostics; using Autodesk.Revit.ApplicationServices;&lt;/P&gt;&lt;P&gt;using Autodesk.Revit.Attributes;&lt;/P&gt;&lt;P&gt;using Autodesk.Revit.DB;&lt;/P&gt;&lt;P&gt;using Autodesk.Revit.UI;&lt;/P&gt;&lt;P&gt;using Autodesk.Revit.UI.Selection;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;P&gt;Bob V&lt;/P&gt;</description>
      <pubDate>Thu, 11 Sep 2014 00:45:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/update-revit-errors/m-p/5266599#M75790</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-09-11T00:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: Update Revit errors</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/update-revit-errors/m-p/5266849#M75791</link>
      <description>&lt;P&gt;It looks like you have some confusion regarding the different types of document objects and the namespace of certain classes.&lt;/P&gt;&lt;P&gt;I'll run quickly through the issues I can see in order and then provide a working example below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't see the &lt;STRONG&gt;application&lt;/STRONG&gt;&amp;nbsp;object being declared or passed into your method, is it declared in the class itself? What is its type? It doesn't look to be a standard API class so I'm assuming it's a custom container / helper class. To get at the Database level document&amp;nbsp;you need to dive into the &lt;STRONG&gt;commandData&lt;/STRONG&gt; parameter that is passed into the method by the API. &lt;STRONG&gt;commandData.Application.ActiveUIDocument.Document&lt;/STRONG&gt; is what you need for that, but as I note&amp;nbsp;in my next point I don't think this is actually what you wanted to do.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The &lt;STRONG&gt;rvtDoc&lt;/STRONG&gt; object&amp;nbsp;looks to be of the wrong class for what you are trying to do with it. The UI level document class&amp;nbsp;is the one that contains the &lt;STRONG&gt;Selection&lt;/STRONG&gt; property, you are trying to use the DB level document.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ElementSet&lt;/STRONG&gt; is found in the &lt;STRONG&gt;Autodesk.Revit.DB&lt;/STRONG&gt; namespace, not Revit. You already have the DB namespace declared so ElementSet alone will suffice.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As above, &lt;STRONG&gt;Element&lt;/STRONG&gt; is also a member of the&amp;nbsp;&lt;SPAN&gt;&lt;STRONG&gt;Autodesk.Revit.DB&lt;/STRONG&gt; namespace, you already have this declared, so Element is just fine&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are defining &lt;STRONG&gt;selSet&lt;/STRONG&gt; twice in the same context, the second declaration and assignment looks to be unintentional and not needed, remove it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Selection.Elements&lt;/STRONG&gt; has been depreciated in the 2015 API, it will still work, but you'll need to revisit any code that uses it in a future release as it will no doubt be removed at some point. Best to use &lt;STRONG&gt;Selection.GetElementIds()&lt;/STRONG&gt; instead and then use the ids to query the database Document for the actual Elements. For simplicity, I'll leave this alone in my example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am assuming that the using directives are at the top your file and you have just pasted them below for readability, if not, move them to the top of the source file, outside of the class declaration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As promised here's one that will work better.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Public Result Execute(ExternalCommandData commandData,ref string message,ElementSet elements)
{
UIDocument rvtDoc = commandData.Application.ActiveUIDocument;
ElementSet selSet = rvtDoc.Selection.Elements;
Element elem = default(Element);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While this will fix the code snippet you pasted, if further down the method you are dealing with rvtDoc as if it was a database document, you will get a new set of errors. If this happens just add &lt;STRONG&gt;Document dbDoc =&amp;nbsp;&lt;/STRONG&gt;&lt;SPAN&gt;&lt;STRONG&gt;commandData.Application.ActiveUIDocument.Document;&lt;/STRONG&gt; at the top of the method and update the affected code to suit.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Sep 2014 04:49:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/update-revit-errors/m-p/5266849#M75791</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2014-09-11T04:49:55Z</dc:date>
    </item>
  </channel>
</rss>

