<?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 Register a switch between open documents? in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/register-a-switch-between-open-documents/m-p/5816144#M70477</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am hoping to to know if there is any way to tell if &lt;U&gt;the user has switched between two &lt;STRONG&gt;open&lt;/STRONG&gt; documents?&lt;/U&gt;&lt;/P&gt;&lt;P&gt;I can't see anything in Database Events that would allow me do this, Could the &lt;U&gt;ViewActivated &lt;/U&gt;event be used to achieve the same goal?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
    <pubDate>Mon, 14 Sep 2015 17:20:01 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2015-09-14T17:20:01Z</dc:date>
    <item>
      <title>Register a switch between open documents?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/register-a-switch-between-open-documents/m-p/5816144#M70477</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am hoping to to know if there is any way to tell if &lt;U&gt;the user has switched between two &lt;STRONG&gt;open&lt;/STRONG&gt; documents?&lt;/U&gt;&lt;/P&gt;&lt;P&gt;I can't see anything in Database Events that would allow me do this, Could the &lt;U&gt;ViewActivated &lt;/U&gt;event be used to achieve the same goal?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 17:20:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/register-a-switch-between-open-documents/m-p/5816144#M70477</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-09-14T17:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: Register a switch between open documents?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/register-a-switch-between-open-documents/m-p/5816187#M70478</link>
      <description>&lt;P&gt;Apologies for premature posting using the ViewActivatedEvent does solve this problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is the code so this post is at least a bit helpful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        public Result OnStartup(UIControlledApplication a)&lt;BR /&gt;        {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a.ViewActivated += new EventHandler&amp;lt;Autodesk.Revit.UI.Events.ViewActivatedEventArgs&amp;gt;(OnViewActivated);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return Result.Succeeded;&lt;BR /&gt;        }&lt;BR /&gt;        public void OnViewActivated(object sender, Autodesk.Revit.UI.Events.ViewActivatedEventArgs args)
        {
            Document doc = &lt;STRONG&gt;args.CurrentActiveView.Document&lt;/STRONG&gt;;
            UIApplication uiapp = new UIApplication(doc.Application);
            Application app = uiapp.Application;&lt;BR /&gt;&lt;BR /&gt;            ...&lt;BR /&gt;            ...&lt;BR /&gt;            //handler code &lt;BR /&gt;            ...&lt;BR /&gt;            ...    &lt;BR /&gt;        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 17:36:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/register-a-switch-between-open-documents/m-p/5816187#M70478</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-09-14T17:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: Register a switch between open documents?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/register-a-switch-between-open-documents/m-p/5816195#M70479</link>
      <description>&lt;P&gt;Hi Mendo,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Great &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; thanks for sharing your answer to your own question. I have found that when you post your questions, there is a good chance you answer it yourself since you will be thinking out loud &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; so great for this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will blog about it to share your answer and make the post more useful than what already is :).&lt;/P&gt;</description>
      <pubDate>Mon, 14 Sep 2015 17:40:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/register-a-switch-between-open-documents/m-p/5816195#M70479</guid>
      <dc:creator>rosalesduquej</dc:creator>
      <dc:date>2015-09-14T17:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: Register a switch between open documents?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/register-a-switch-between-open-documents/m-p/5816210#M70480</link>
      <description>I guess I need to jump in before an incorrect solution is published somewhere else.&lt;BR /&gt;&lt;BR /&gt;The suggested solution is only partially correct. The ViewActivated can indeed be used to capture moments when the end user switches from one visible document to another. The implementation of the event's handler is wrong, however. Programmers are not permitted to instantiate Revit application objects! It is a singleton and can only be instantiated once per session (Revit does it at startup.) In fact, an attempt to do so will throw an exception in 2016 and later releases. To get to the Application, the programmer has two options:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;a)      The sender of the event is UIApplication - thus the programmer can recast it&lt;BR /&gt;&lt;BR /&gt;b)      An instance of Application (the DB kind) can be obtained from the Document instance.&lt;BR /&gt;&lt;BR /&gt;Thank you&lt;BR /&gt;Arno?t L?bel</description>
      <pubDate>Mon, 14 Sep 2015 17:51:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/register-a-switch-between-open-documents/m-p/5816210#M70480</guid>
      <dc:creator>arnostlobel</dc:creator>
      <dc:date>2015-09-14T17:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: Register a switch between open documents?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/register-a-switch-between-open-documents/m-p/5817163#M70481</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what about:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;private void viewActivated(object sender, ViewActivatedEventArgs args)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if ((args.PreviousActiveView != null) &amp;amp;&amp;amp; (args.PreviousActiveView.Document != null)) // start screen has neither view nor document&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if (args.PreviousActiveView.Document.PathName != args.CurrentActiveView.Document.PathName)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;// document has been switched&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note:&lt;/P&gt;&lt;P&gt;As for worksharing environments, Document.PathName is empty, as far as I know.&lt;/P&gt;&lt;P&gt;Either compare ModelPaths or just the Document.Title property:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;private void viewActivated(object sender, ViewActivatedEventArgs args)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if ((args.PreviousActiveView != null) &amp;amp;&amp;amp; (args.PreviousActiveView.Document != null)) // start screen has neither view nor document&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if (args.PreviousActiveView.Document.Title != args.CurrentActiveView.Document.Title)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;// document has been switched&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Revitalizer&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2015 07:42:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/register-a-switch-between-open-documents/m-p/5817163#M70481</guid>
      <dc:creator>Revitalizer</dc:creator>
      <dc:date>2015-09-15T07:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Register a switch between open documents?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/register-a-switch-between-open-documents/m-p/5817705#M70482</link>
      <description>Revitalizer,&lt;BR /&gt;&lt;BR /&gt;There is no need to rely on either the Path or Title property in order to compare two currently open documents. The Document.Equals method should handle the comparison just fine. Thus, if the document of the previously active view does not equal the document of the currently active view, then an active document switch has just happened.&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;&lt;BR /&gt;Arno?t</description>
      <pubDate>Tue, 15 Sep 2015 14:46:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/register-a-switch-between-open-documents/m-p/5817705#M70482</guid>
      <dc:creator>arnostlobel</dc:creator>
      <dc:date>2015-09-15T14:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: Register a switch between open documents?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/register-a-switch-between-open-documents/m-p/5817744#M70483</link>
      <description>&lt;P&gt;Dear Arnost,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you for pointing this out.&lt;/P&gt;&lt;P&gt;I didn't know that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In fact, I usually don't rely on the Equals method.&lt;/P&gt;&lt;P&gt;Some years ago, for example, this method didn't work when comparing ElementIds, so I used to compare their IntegerValues.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Revitalizer&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2015 14:59:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/register-a-switch-between-open-documents/m-p/5817744#M70483</guid>
      <dc:creator>Revitalizer</dc:creator>
      <dc:date>2015-09-15T14:59:55Z</dc:date>
    </item>
    <item>
      <title>Re: Register a switch between open documents?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/register-a-switch-between-open-documents/m-p/5817773#M70484</link>
      <description>Not relying on the standard Equals method is generally the recommended approach, as there is a lot of inconsistencies in the Revit API. However, we had made sure the comparison works for Documents especially because it is rather difficult to compare documents using other ways.&lt;BR /&gt;&lt;BR /&gt;Arno?t</description>
      <pubDate>Tue, 15 Sep 2015 15:13:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/register-a-switch-between-open-documents/m-p/5817773#M70484</guid>
      <dc:creator>arnostlobel</dc:creator>
      <dc:date>2015-09-15T15:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: Register a switch between open documents?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/register-a-switch-between-open-documents/m-p/5819114#M70485</link>
      <description>&lt;P&gt;Hi Arnost and all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;to sum it up, this is my candidate for the solution of this thread:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;private void viewActivated(object sender, ViewActivatedEventArgs args)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if ((args.PreviousActiveView != null) &amp;amp;&amp;amp; (args.PreviousActiveView.Document != null)) // start screen has neither view nor document&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if (!args.PreviousActiveView.Document.Equals(args.CurrentActiveView.Document))&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;// document has been switched&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Revitalizer&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2015 10:19:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/register-a-switch-between-open-documents/m-p/5819114#M70485</guid>
      <dc:creator>Revitalizer</dc:creator>
      <dc:date>2015-09-16T10:19:12Z</dc:date>
    </item>
  </channel>
</rss>

