<?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: Events in the API in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/events-in-the-api/m-p/2354737#M149335</link>
    <description>&lt;DIV id="jive-html-wrapper-div"&gt;
&lt;BR /&gt;
&lt;DIV&gt;&lt;FONT face="Arial" size="2"&gt;My latest blog posting shows how to listen to an &lt;BR /&gt;
event in C#.&amp;nbsp; Check out &lt;A&gt;&lt;BR /&gt;
href="http://modthemachine.typepad.com/"&amp;gt;http://modthemachine.typepad.com&lt;/A&gt;&lt;BR /&gt;-- &lt;BR /&gt;
&lt;BR /&gt;Brian Ekins&lt;BR /&gt;Autodesk Inventor API&lt;BR /&gt;&lt;A&gt;&lt;BR /&gt;
href="http://modthemachine.typepad.com"&amp;gt;http://modthemachine.typepad.com&lt;/A&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;BR /&gt;
&lt;DIV&gt;&lt;FONT face="Arial" size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;BR /&gt;
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px"&amp;gt;&lt;BR /&gt;
  &lt;DIV&gt;&amp;lt;Simonsson&amp;gt; wrote in message &lt;A&gt;&lt;BR /&gt;
  href="news:6044220@discussion.autodesk.com"&amp;gt;news:6044220@discussion.autodesk.com&lt;/A&gt;...&lt;/DIV&gt;I'm &lt;BR /&gt;
  working with an Inventor addin (C#), but I have problems with the events. I &lt;BR /&gt;
  use the Inventor 2009 API Reference, but the syntax is in VB or something. For &lt;BR /&gt;
  instance:&lt;BR /&gt;&lt;BR /&gt;Public Event OnFileNew( _&lt;BR /&gt;ByVal DocumentType As &lt;BR /&gt;
  DocumentTypeEnum, _&lt;BR /&gt;ByRef TemplateFileName As String, _&lt;BR /&gt;ByVal Context As &lt;BR /&gt;
  NameValueMap, _&lt;BR /&gt;ByRef HandlingCode As HandlingCodeEnum _&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;In C# &lt;BR /&gt;
  the "ByVal" seems to be default so I don't have to write anything there. But &lt;BR /&gt;
  "ByRef" can be both "ref" and "out" it seems. My problem is to translate this &lt;BR /&gt;
  syntax to C#. I managed to translate this OnFileNew event, but generally - how &lt;BR /&gt;
  do I know that "ByRef TemplateFileName As String" should be "ref string &lt;BR /&gt;
  TemplateFileName" and that "ByRef HandlingCode As HandlingCodeEnum" should be &lt;BR /&gt;
  "out HandlingCodeEnum HandlingCode"?&lt;BR /&gt;&lt;BR /&gt;It seems just to be a matter of &lt;BR /&gt;
  syntax, so is there any way to autogenerate this code? I use Visual Studio &lt;BR /&gt;
  2005. First I do this:&lt;BR /&gt;&lt;BR /&gt;fileUIEvents.OnFileNewDialog += new &lt;BR /&gt;
  FileUIEventsSink_OnFileNewDialogEventHandler(fileUIEvents_OnFileNewDialog);&lt;BR /&gt;&lt;BR /&gt;And &lt;BR /&gt;
  here I get problems:&lt;BR /&gt;&lt;BR /&gt;void fileUIEvents_OnFileInsertNewDialog( &lt;BR /&gt;
  [PROBLEMS] );&lt;BR /&gt;&lt;BR /&gt;Error 1 No overload for 'fileUIEvents_OnFileNewDialog' &lt;BR /&gt;
  matches delegate &lt;BR /&gt;
'Inventor.FileUIEventsSink_OnFileNewDialogEventHandler'&lt;/BLOCKQUOTE&gt;
&lt;/DIV&gt;</description>
    <pubDate>Fri, 03 Oct 2008 17:04:25 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2008-10-03T17:04:25Z</dc:date>
    <item>
      <title>Events in the API</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/events-in-the-api/m-p/2354736#M149334</link>
      <description>I'm working with an Inventor addin (C#), but I have problems with the events. I use the Inventor 2009 API Reference, but the syntax is in VB or something. For instance:&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
Public Event OnFileNew( _&lt;BR /&gt;&lt;BR /&gt;
   ByVal DocumentType As DocumentTypeEnum, _&lt;BR /&gt;&lt;BR /&gt;
   ByRef TemplateFileName As String, _&lt;BR /&gt;&lt;BR /&gt;
   ByVal Context As NameValueMap, _&lt;BR /&gt;&lt;BR /&gt;
   ByRef HandlingCode As HandlingCodeEnum _&lt;BR /&gt;&lt;BR /&gt;
)&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
In C# the "ByVal" seems to be default so I don't have to write anything there. But "ByRef" can be both "ref" and "out" it seems. My problem is to translate this syntax to C#. I managed to translate this OnFileNew event, but generally - how do I know that "ByRef TemplateFileName As String" should be "ref string TemplateFileName" and that "ByRef HandlingCode As HandlingCodeEnum" should be "out HandlingCodeEnum HandlingCode"?&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
It seems just to be a matter of syntax, so is there any way to autogenerate this code? I use Visual Studio 2005. First I do this:&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
fileUIEvents.OnFileNewDialog += new FileUIEventsSink_OnFileNewDialogEventHandler(fileUIEvents_OnFileNewDialog);&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
And here I get problems:&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
void fileUIEvents_OnFileInsertNewDialog( [PROBLEMS] );&lt;BR /&gt;&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;
Error	1	No overload for 'fileUIEvents_OnFileNewDialog' matches delegate 'Inventor.FileUIEventsSink_OnFileNewDialogEventHandler'</description>
      <pubDate>Fri, 03 Oct 2008 07:29:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/events-in-the-api/m-p/2354736#M149334</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-10-03T07:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: Events in the API</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/events-in-the-api/m-p/2354737#M149335</link>
      <description>&lt;DIV id="jive-html-wrapper-div"&gt;
&lt;BR /&gt;
&lt;DIV&gt;&lt;FONT face="Arial" size="2"&gt;My latest blog posting shows how to listen to an &lt;BR /&gt;
event in C#.&amp;nbsp; Check out &lt;A&gt;&lt;BR /&gt;
href="http://modthemachine.typepad.com/"&amp;gt;http://modthemachine.typepad.com&lt;/A&gt;&lt;BR /&gt;-- &lt;BR /&gt;
&lt;BR /&gt;Brian Ekins&lt;BR /&gt;Autodesk Inventor API&lt;BR /&gt;&lt;A&gt;&lt;BR /&gt;
href="http://modthemachine.typepad.com"&amp;gt;http://modthemachine.typepad.com&lt;/A&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;BR /&gt;
&lt;DIV&gt;&lt;FONT face="Arial" size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;BR /&gt;
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px"&amp;gt;&lt;BR /&gt;
  &lt;DIV&gt;&amp;lt;Simonsson&amp;gt; wrote in message &lt;A&gt;&lt;BR /&gt;
  href="news:6044220@discussion.autodesk.com"&amp;gt;news:6044220@discussion.autodesk.com&lt;/A&gt;...&lt;/DIV&gt;I'm &lt;BR /&gt;
  working with an Inventor addin (C#), but I have problems with the events. I &lt;BR /&gt;
  use the Inventor 2009 API Reference, but the syntax is in VB or something. For &lt;BR /&gt;
  instance:&lt;BR /&gt;&lt;BR /&gt;Public Event OnFileNew( _&lt;BR /&gt;ByVal DocumentType As &lt;BR /&gt;
  DocumentTypeEnum, _&lt;BR /&gt;ByRef TemplateFileName As String, _&lt;BR /&gt;ByVal Context As &lt;BR /&gt;
  NameValueMap, _&lt;BR /&gt;ByRef HandlingCode As HandlingCodeEnum _&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;In C# &lt;BR /&gt;
  the "ByVal" seems to be default so I don't have to write anything there. But &lt;BR /&gt;
  "ByRef" can be both "ref" and "out" it seems. My problem is to translate this &lt;BR /&gt;
  syntax to C#. I managed to translate this OnFileNew event, but generally - how &lt;BR /&gt;
  do I know that "ByRef TemplateFileName As String" should be "ref string &lt;BR /&gt;
  TemplateFileName" and that "ByRef HandlingCode As HandlingCodeEnum" should be &lt;BR /&gt;
  "out HandlingCodeEnum HandlingCode"?&lt;BR /&gt;&lt;BR /&gt;It seems just to be a matter of &lt;BR /&gt;
  syntax, so is there any way to autogenerate this code? I use Visual Studio &lt;BR /&gt;
  2005. First I do this:&lt;BR /&gt;&lt;BR /&gt;fileUIEvents.OnFileNewDialog += new &lt;BR /&gt;
  FileUIEventsSink_OnFileNewDialogEventHandler(fileUIEvents_OnFileNewDialog);&lt;BR /&gt;&lt;BR /&gt;And &lt;BR /&gt;
  here I get problems:&lt;BR /&gt;&lt;BR /&gt;void fileUIEvents_OnFileInsertNewDialog( &lt;BR /&gt;
  [PROBLEMS] );&lt;BR /&gt;&lt;BR /&gt;Error 1 No overload for 'fileUIEvents_OnFileNewDialog' &lt;BR /&gt;
  matches delegate &lt;BR /&gt;
'Inventor.FileUIEventsSink_OnFileNewDialogEventHandler'&lt;/BLOCKQUOTE&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 03 Oct 2008 17:04:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/events-in-the-api/m-p/2354737#M149335</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-10-03T17:04:25Z</dc:date>
    </item>
    <item>
      <title>Re: Events in the API</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/events-in-the-api/m-p/3755252#M149336</link>
      <description>&lt;P&gt;Brians links seems to be broken, and I can´t find any information on delegates in the help file or VBA objectbrowser.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It might be due to some esoteric self-explanatory convention within C# / COM, but for newcomers as myself a straight forward explanation on the delegate naming would be great and welcome.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Going through several samples and module 10 from the API virtual training videos, I asume it works like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Object.Event &amp;nbsp;: &amp;nbsp;&lt;FONT color="#0000FF"&gt;XXEvents.OnXX(arguments)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Delegate : &amp;nbsp;&lt;FONT color="#0000FF"&gt;XXEvents&lt;/FONT&gt;&lt;EM&gt;&lt;FONT color="#FF0000"&gt;Sink_&lt;/FONT&gt;&lt;/EM&gt;&lt;FONT color="#0000ff"&gt;OnXX&lt;/FONT&gt;&lt;EM&gt;&lt;FONT color="#FF0000"&gt;EventHandler&lt;/FONT&gt;&lt;/EM&gt;&lt;FONT color="#FF0000"&gt;(&lt;/FONT&gt;&lt;FONT color="#99CC00"&gt;handler&lt;/FONT&gt;&lt;FONT color="#FF0000"&gt;)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Handler : &lt;FONT color="#99CC00"&gt;handler&lt;/FONT&gt;&lt;FONT color="#0000FF"&gt;(arguments)&lt;/FONT&gt;&lt;FONT color="#99CC00"&gt;{ code }&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this understood correctly and if yes, is it consistent throughout the API ?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2013 10:07:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/events-in-the-api/m-p/3755252#M149336</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-01-17T10:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: Events in the API</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/events-in-the-api/m-p/3755999#M149337</link>
      <description>&lt;P&gt;In my experience the naming follows the convention you describe. In practice, you may not need the delegate name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// C#&lt;/P&gt;&lt;P&gt;// keep reference to event manager&lt;/P&gt;&lt;P&gt;XXEvents events = ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// subscribe&lt;/P&gt;&lt;P&gt;events.OnXX += handler&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// unsubscribe&lt;/P&gt;&lt;P&gt;events.OnXX -= handler&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From the documentation it seems we need to maintain a reference to the event manager XXEvents so that garbage collection does not remove the subscribed handlers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The other catch to be aware of is it is not safe to unsubscribe during the handler execution. Doing so can cause the execution of other subscribed handlers to be skipped. I haven't tested whether this impacts all handlers of an event (e.g. Inventor and other add-ins) or if it is just limited to subscriptions from the same add-in.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// multiple subscriptions&lt;/P&gt;&lt;P&gt;events.OnXX += handler1&lt;/P&gt;&lt;P&gt;events.OnXX += handler2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// in hander1&lt;/P&gt;&lt;P&gt;events.OnXX -= handler1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// handler2 is not executed&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;cadull&lt;/P&gt;</description>
      <pubDate>Thu, 17 Jan 2013 22:24:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/events-in-the-api/m-p/3755999#M149337</guid>
      <dc:creator>cadull_rb</dc:creator>
      <dc:date>2013-01-17T22:24:46Z</dc:date>
    </item>
    <item>
      <title>Re: Events in the API</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/events-in-the-api/m-p/3756551#M149338</link>
      <description>&lt;P&gt;Thanks for the reply..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your right :In practice I don´t need the names as VS&amp;nbsp;pops them up. ( I was studying before executing )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;amp; thanks for the additional information.. It will most likely save me days of confusion later on!&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jan 2013 15:14:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/events-in-the-api/m-p/3756551#M149338</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-01-18T15:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Events in the API</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/events-in-the-api/m-p/9325430#M149339</link>
      <description>&lt;P&gt;The GC had made me Headaches. Holding an explicite Reference to the Document.DocumentEvents Object fixed it!&lt;/P&gt;&lt;P&gt;Never had&amp;nbsp; figured this out by myself &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2020 14:42:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/events-in-the-api/m-p/9325430#M149339</guid>
      <dc:creator>dba78</dc:creator>
      <dc:date>2020-02-18T14:42:13Z</dc:date>
    </item>
  </channel>
</rss>

