<?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 OnNewDocument  Firing Multiple Times in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/onnewdocument-firing-multiple-times/m-p/5470500#M53602</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to capture the application event OnNew Document to provide some actions after the new file has been created.&lt;/P&gt;&lt;P&gt;What I am experiencing is that when capturing the event and then filtering to repond the event is fired upto 3 times with &lt;STRONG&gt;BeforeOrAfter &lt;/STRONG&gt;= &lt;STRONG&gt;After&lt;/STRONG&gt;. This is occurring when the&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My routine takes the form (not actual Vb code)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Public Sub OnNewDocument( DocumentObject As Document, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, HandlingCode As HandlingCodeEnum )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if BeforeOrAfter &amp;lt;&amp;gt; kAfter then return&lt;/P&gt;&lt;P&gt;if DocumentObject.document type &amp;lt;&amp;gt; kInventorDrawingDocument then return&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some code to display a dialogue and alter number of sheets in drawing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;End&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What seeems to be occuring is the dialogue, display works, creates the extra sheets, but then is displayed up to 2 times more. This is intermittent and sometimes diplays once, twice or thrice. I beleive the event is triggering this many times as if I strip all my code out and simply show a message box on the event the same happens.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any Clues? I presume Inventor may be making new docs in the background perhaps?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any easy way to filter perhaps on Context data?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards Ian&lt;/P&gt;</description>
    <pubDate>Thu, 15 Jan 2015 10:56:52 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2015-01-15T10:56:52Z</dc:date>
    <item>
      <title>OnNewDocument  Firing Multiple Times</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/onnewdocument-firing-multiple-times/m-p/5470500#M53602</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to capture the application event OnNew Document to provide some actions after the new file has been created.&lt;/P&gt;&lt;P&gt;What I am experiencing is that when capturing the event and then filtering to repond the event is fired upto 3 times with &lt;STRONG&gt;BeforeOrAfter &lt;/STRONG&gt;= &lt;STRONG&gt;After&lt;/STRONG&gt;. This is occurring when the&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My routine takes the form (not actual Vb code)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Public Sub OnNewDocument( DocumentObject As Document, BeforeOrAfter As EventTimingEnum, Context As NameValueMap, HandlingCode As HandlingCodeEnum )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if BeforeOrAfter &amp;lt;&amp;gt; kAfter then return&lt;/P&gt;&lt;P&gt;if DocumentObject.document type &amp;lt;&amp;gt; kInventorDrawingDocument then return&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some code to display a dialogue and alter number of sheets in drawing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;End&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What seeems to be occuring is the dialogue, display works, creates the extra sheets, but then is displayed up to 2 times more. This is intermittent and sometimes diplays once, twice or thrice. I beleive the event is triggering this many times as if I strip all my code out and simply show a message box on the event the same happens.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any Clues? I presume Inventor may be making new docs in the background perhaps?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any easy way to filter perhaps on Context data?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards Ian&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jan 2015 10:56:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/onnewdocument-firing-multiple-times/m-p/5470500#M53602</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-01-15T10:56:52Z</dc:date>
    </item>
    <item>
      <title>Re: OnNewDocument  Firing Multiple Times</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/onnewdocument-firing-multiple-times/m-p/5481710#M53758</link>
      <description>&lt;P&gt;Hi Ian,&lt;/P&gt;&lt;P&gt;this is a piece of VB.net code of&amp;nbsp;my addins, may this help you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;' variables declarations&lt;BR /&gt;Private&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN&gt;WithEvents&lt;/SPAN&gt;&amp;nbsp;m_appEvents&amp;nbsp;&lt;SPAN&gt;As&lt;/SPAN&gt;&amp;nbsp;Inventor.&lt;SPAN&gt;ApplicationEvents&lt;/SPAN&gt;
&lt;BR /&gt;' some code&lt;BR /&gt;&lt;BR /&gt;Private Sub m_appEvents_OnNewDocument(ByVal DocumentObject As Inventor._Document, ByVal BeforeOrAfter As Inventor.EventTimingEnum, _ ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles m_appEvents.OnNewDocument
   Try
     If BeforeOrAfter = EventTimingEnum.kBefore Then 
       ' some code
    End If
   Catch ex As Exception
   End Try
  HandlingCode = HandlingCodeEnum.kEventHandled
End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bregs&lt;/P&gt;&lt;P&gt;Rossano Praderi&lt;/P&gt;</description>
      <pubDate>Sun, 25 Jan 2015 18:28:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/onnewdocument-firing-multiple-times/m-p/5481710#M53758</guid>
      <dc:creator>rossano_praderi</dc:creator>
      <dc:date>2015-01-25T18:28:17Z</dc:date>
    </item>
  </channel>
</rss>

