<?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: Registering a Revit Event handler using VB in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/registering-a-revit-event-handler-using-vb/m-p/6473341#M63728</link>
    <description>&lt;P&gt;I'm lost when it comes to C#... What I posted was directly out of an example from Dev Labs (or maybe it was from the building Coder... or maybe from the samples in the SDK... or maybe from the API help...&amp;nbsp;that's the problem with trying to figure anything out with the Revit API: no single clear and concise resource). So I assume that what I posted was the correct method and I have been trying to emulate it in VB.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-G&lt;/P&gt;</description>
    <pubDate>Tue, 02 Aug 2016 15:09:28 GMT</pubDate>
    <dc:creator>Gary_J_Orr</dc:creator>
    <dc:date>2016-08-02T15:09:28Z</dc:date>
    <item>
      <title>Registering a Revit Event handler using VB</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/registering-a-revit-event-handler-using-vb/m-p/6471303#M63725</link>
      <description>&lt;P&gt;I've searched, tried language conversion utilities, etc., etc... I simply can't find a working example (or anything in any version of help for the API on any site or in the Labs) of registering for Revit events.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The C# method would be:&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;thisApp.ControlledApplication.&lt;/FONT&gt;DocumentCreated&lt;FONT face="Consolas" size="2"&gt; += &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;New&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;EventHandler&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Of&lt;/FONT&gt; DocumentCreatedEventArgs&lt;FONT face="Consolas" size="2"&gt;)(eventHandlerMethod)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;or:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Consolas" size="2"&gt;thisApp.ViewActivated += &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;New&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;EventHandler&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Consolas" size="2"&gt;Of&lt;/FONT&gt; &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;ViewActivatedEventArgs&lt;/FONT&gt;&lt;FONT face="Consolas" size="2"&gt;)(eventHandlerMethod)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe that the += and -= for registering and unregistering events needs to be replaced with AddHandler and RemoveHandler in VB but I have been unable to find the correct synax and requirements&amp;nbsp;for what needs to be/ can be passed to the handler function. From the C# examples and documentation I know that the eventHandlerMethod should be able to receive the sending object and the event arguments themselves.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Intellisense and Microsoft help tells me that the AddHandler function should look something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;AddHandler thisApp.ControlledApplication.DocumentCreating, AddressOf (eventHandlerMethod(origObject, DocumentCreatedEventArgs))&lt;/P&gt;&lt;P&gt;or:&lt;/P&gt;&lt;P&gt;AddHandler thisApp.&lt;FONT face="Consolas" size="2"&gt;ViewActivated&lt;/FONT&gt;, AddressOf (eventHandlerMethod(origObject, &lt;FONT color="#2b91af" face="Consolas" size="2"&gt;ViewActivatedEventArgs&lt;/FONT&gt;))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So how do I pass the event arguments (and, in the case of an modified object, the object that was modified... I know, I didn't provide such an example but, just thinking ahead here)&amp;nbsp;to my&amp;nbsp;"eventHandlerMethod" (as used in my example)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Gary&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2016 18:10:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/registering-a-revit-event-handler-using-vb/m-p/6471303#M63725</guid>
      <dc:creator>Gary_J_Orr</dc:creator>
      <dc:date>2016-08-01T18:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: Registering a Revit Event handler using VB</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/registering-a-revit-event-handler-using-vb/m-p/6472011#M63726</link>
      <description>&lt;P&gt;Hi Gary,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems like you've discovered that these event handlers are delegate instances. If that isn't necessarily the case: &lt;A href="https://msdn.microsoft.com/en-us/library/ms172879.aspx" target="_blank"&gt;https://msdn.microsoft.com/en-us/library/ms172879.aspx&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;In adding the event handler you only need to pass the function which you intend to handle the event, no need to specify the arguments because the arguments are already specified by the delegate type declaration&lt;BR /&gt;more on delegates here: &lt;A href="https://msdn.microsoft.com/en-us/library/aa288459(v=vs.71).aspx" target="_blank"&gt;https://msdn.microsoft.com/en-us/library/aa288459(v=vs.71).aspx&lt;/A&gt;&lt;BR /&gt;Also, C#4.0 The Complete Reference has a great section on delegates that might help clarify.&lt;BR /&gt;&lt;BR /&gt;When Revit calls your event handler it will pass in the pre-agreed upon arguments (as defined in the delegate type aka event) EventHandlers in .NET (I believe), are myEventHandler(object sender, EventArgs args) which allows you to define your own event handlers with this pattern of arguments which makes your "handler" function a "match" for the delegate type declaration for which you intend it to be a handler..&lt;BR /&gt;&lt;BR /&gt;Here's another good read:&lt;BR /&gt;&lt;A href="http://stackoverflow.com/questions/803242/understanding-events-and-event-handlers-in-c-sharp" target="_blank"&gt;http://stackoverflow.com/questions/803242/understanding-events-and-event-handlers-in-c-sharp&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;All that should, in theory, be transmutatable to VB. (I am most definitely NOT and expert in VB so take that with the requisite grain of salt).&lt;BR /&gt;&lt;BR /&gt;Hope I've understood your question and haven't given you a bunch of information you already know. But in the case that I have please feel free to clarify and we'll try to help however we can.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 01:52:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/registering-a-revit-event-handler-using-vb/m-p/6472011#M63726</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-08-02T01:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: Registering a Revit Event handler using VB</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/registering-a-revit-event-handler-using-vb/m-p/6472016#M63727</link>
      <description>oh, I just noticed that what you suggested for C# event handler registration isn't quite what we might expect to see. In C# to add an event handler it looks a lot like this:&lt;BR /&gt;revitApp.ControlledApplication.DocumentOpened += myDocOpenedHandler;&lt;BR /&gt;&lt;BR /&gt;Note, there is no mention of arguments as they've already been agreed upon by the delegate type e.g. (object sender, DocuemntOpenedEventArgs [or something like that]) and the myDocOpenedHandler function definition just needs to adopt that set of parameters to be a "match"</description>
      <pubDate>Tue, 02 Aug 2016 01:57:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/registering-a-revit-event-handler-using-vb/m-p/6472016#M63727</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-08-02T01:57:15Z</dc:date>
    </item>
    <item>
      <title>Re: Registering a Revit Event handler using VB</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/registering-a-revit-event-handler-using-vb/m-p/6473341#M63728</link>
      <description>&lt;P&gt;I'm lost when it comes to C#... What I posted was directly out of an example from Dev Labs (or maybe it was from the building Coder... or maybe from the samples in the SDK... or maybe from the API help...&amp;nbsp;that's the problem with trying to figure anything out with the Revit API: no single clear and concise resource). So I assume that what I posted was the correct method and I have been trying to emulate it in VB.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-G&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 15:09:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/registering-a-revit-event-handler-using-vb/m-p/6473341#M63728</guid>
      <dc:creator>Gary_J_Orr</dc:creator>
      <dc:date>2016-08-02T15:09:28Z</dc:date>
    </item>
    <item>
      <title>Re: Registering a Revit Event handler using VB</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/registering-a-revit-event-handler-using-vb/m-p/6473570#M63729</link>
      <description>&lt;P&gt;Hi Gary,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand that it can be frustrating: Please realize I'm only trying to help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The "Of" keyword in the C# example is not a keyword of C# language (&lt;A href="https://msdn.microsoft.com/en-us/library/x53a06bb.aspx" target="_blank"&gt;https://msdn.microsoft.com/en-us/library/x53a06bb.aspx&lt;/A&gt;) it is rather a keyword of VB(&lt;A href="https://msdn.microsoft.com/en-us/library/ksh7h19t(v=vs.90).aspx" target="_blank"&gt;https://msdn.microsoft.com/en-us/library/ksh7h19t(v=vs.90).aspx&lt;/A&gt;) so the statement:&lt;/P&gt;&lt;PRE&gt;//The C# method would be:
thisApp.ControlledApplication.DocumentCreated += New EventHandler(Of DocumentCreatedEventArgs)(eventHandlerMethod)&lt;/PRE&gt;&lt;P&gt;is not a C# event handler registration.&amp;nbsp; it would be like this:&lt;/P&gt;&lt;PRE&gt;thisApp.ControlledApplication.DocumentCreated += eventHandlerMethod;&lt;/PRE&gt;&lt;P&gt;the equivalent in VB:&lt;/P&gt;&lt;PRE&gt;AddHandler thisApp.ControlledApplication.DocumentCreated, AddressOf eventHandlerMethod

'with a function declared:
Private Sub eventHandlerMethod(ByVal sender As System.Object, ByVal args As DocumentCreatedEventArgs) Handles thisApp.ControlledApplication.DocumentCreated
   ' Add event handler code here.
End Sub&lt;/PRE&gt;&lt;P&gt;if you're trying to figure out how to pass additional arguments/information to the handler as parameters that can be accessed in the handler; you might consider storing that information somewhere (static variables, extensible storage, RevitParameters) or pass an anonymous method as the event handler as shown here &lt;A href="http://stackoverflow.com/questions/4215845/c-sharp-passing-extra-parameters-to-an-event-handler" target="_blank"&gt;http://stackoverflow.com/questions/4215845/c-sharp-passing-extra-parameters-to-an-event-handler&lt;/A&gt; but note that it is (I believe) evaluated at the time of registration.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best of luck with it.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 16:32:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/registering-a-revit-event-handler-using-vb/m-p/6473570#M63729</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-08-02T16:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: Registering a Revit Event handler using VB</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/registering-a-revit-event-handler-using-vb/m-p/6473695#M63730</link>
      <description>&lt;P&gt;Thank ya much Ken... and no, I wasn't bashing you... that was Adesk bashing, sorry if it came across otherwise. I'll give your proposed solution a try as soon as I can get back on the project (got "real" work and all that &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; but I'm sure that you have me on the correct path as this looks more like what I was expecting (both your C# correction for the simplified "direct" handler and the VB version thereof)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In looking at what you mentioned about "anonymous" methods... I think that is what I was trying to decipher from the SDK samples (Revit 2016 SDK\Samples\Events\EventsMonitor) without understanding what they were doing... and that's what was throwing me. They were using one handler for all events to simply log the events within the handler method. This must be the reason for all of the additional declarations within the assignment call.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is also the addition of the "Handles..." within the function itself. The SDK example didn't address this because of how they were creating their handler.&lt;BR /&gt;&lt;BR /&gt;Thanks again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-G&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 17:27:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/registering-a-revit-event-handler-using-vb/m-p/6473695#M63730</guid>
      <dc:creator>Gary_J_Orr</dc:creator>
      <dc:date>2016-08-02T17:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: Registering a Revit Event handler using VB</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/registering-a-revit-event-handler-using-vb/m-p/6474482#M63731</link>
      <description>&lt;P&gt;In VB it is something like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; AddHandler uiApp.ViewActivated, AddressOf ViewActivated&lt;/PRE&gt;&lt;P&gt;And then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Public Function ViewActivated(ByVal sender As Object, ByVal args As Autodesk.Revit.UI.Events.ViewActivatedEventArgs)
        
'your code here.

    End Function&lt;/PRE&gt;&lt;P&gt;I hope that helps?&lt;/P&gt;</description>
      <pubDate>Tue, 02 Aug 2016 23:51:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/registering-a-revit-event-handler-using-vb/m-p/6474482#M63731</guid>
      <dc:creator>PhillipM</dc:creator>
      <dc:date>2016-08-02T23:51:40Z</dc:date>
    </item>
    <item>
      <title>Re: Registering a Revit Event handler using VB</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/registering-a-revit-event-handler-using-vb/m-p/6475560#M63732</link>
      <description>Phillip, yes, I'm sure it will end up being what I need... It's the same as Ken's suggestion (although his includes the "Handles..." in the function definition).&lt;BR /&gt;I just need time to get back into it and apply it.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;-G</description>
      <pubDate>Wed, 03 Aug 2016 13:37:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/registering-a-revit-event-handler-using-vb/m-p/6475560#M63732</guid>
      <dc:creator>Gary_J_Orr</dc:creator>
      <dc:date>2016-08-03T13:37:24Z</dc:date>
    </item>
  </channel>
</rss>

