<?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: Rule running every time the file is opened in Inventor Programming - iLogic, Macros, AddIns &amp; Apprentice</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-running-every-time-the-file-is-opened/m-p/9153594#M103181</link>
    <description>&lt;PRE&gt;&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;doc&lt;/SPAN&gt; = &lt;SPAN&gt;ThisDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Document&lt;/SPAN&gt;
&lt;SPAN&gt;MsgBox&lt;/SPAN&gt; (&lt;SPAN&gt;doc&lt;/SPAN&gt;.&lt;SPAN&gt;FileSaveCounter&lt;/SPAN&gt;)
&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;doc&lt;/SPAN&gt;.&lt;SPAN&gt;FileSaveCounter&lt;/SPAN&gt; = 0 &lt;SPAN&gt;Then&lt;/SPAN&gt;
	
	&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Savecounter.PNG" style="width: 286px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/699151i5B4FF442D7DCA5BB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Savecounter.PNG" alt="Savecounter.PNG" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Nov 2019 20:39:28 GMT</pubDate>
    <dc:creator>bradeneuropeArthur</dc:creator>
    <dc:date>2019-11-18T20:39:28Z</dc:date>
    <item>
      <title>Rule running every time the file is opened</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-running-every-time-the-file-is-opened/m-p/9152188#M103169</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a rule that triggers upon the opening of a file (which in turn has been opened by another rule in a different file) which is what I want the first time round. However, the file then makes a copy of itself and the rule set to trigger at file opening is fired again. My question is, is there a way to suppress the rule running only on the first time or a bit of iLogic code I could implement to help with this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 09:23:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-running-every-time-the-file-is-opened/m-p/9152188#M103169</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-11-18T09:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: Rule running every time the file is opened</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-running-every-time-the-file-is-opened/m-p/9152689#M103171</link>
      <description>&lt;P&gt;could you share your code, so we can complete the code for you?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 14:17:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-running-every-time-the-file-is-opened/m-p/9152689#M103171</guid>
      <dc:creator>bradeneuropeArthur</dc:creator>
      <dc:date>2019-11-18T14:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: Rule running every time the file is opened</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-running-every-time-the-file-is-opened/m-p/9152762#M103172</link>
      <description>&lt;P&gt;You're right, thank you. The bold section is where the file copy is created, saved and checked in to Vault. When it is created, it goes through an Event Triggered piece of code which starts the sketch process for a base drawing. To either stop the base drawing process at this point or limit it to one go or something like that is what I'm after. Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Dim modelname As String
Dim odoc As Document


iLogicForm.Show("Save Drawing")

modelname = iProperties.Value("Summary", "Title")

If saved = True Then
	ThisDoc.Document.saveasinventordwg("[MACHINE DRAWING FIEPATH]" &amp;amp; modelname &amp;amp; ".dwg", True)
	
	oFileName = ThisDoc.FileName(False) 'without extension
	oRevNum = iProperties.Value("Project", "Revision Number")
	oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
	oDocument = ThisApplication.ActiveDocument
	oContext = ThisApplication.TransientObjects.CreateTranslationContext
	oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
	oOptions = ThisApplication.TransientObjects.CreateNameValueMap
	oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

	oOptions.Value("All_Color_AS_Black") = 1
	oOptions.Value("Remove_Line_Weights") = 1
	oOptions.Value("Vector_Resolution") = 400
	oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets

	'get PDF target folder path
	oFolder = "[PDF DRAWING FILEPATH]"

	'Check for the PDF folder and create it if it does not exist
	If Not System.IO.Directory.Exists(oFolder) Then
	    System.IO.Directory.CreateDirectory(oFolder)
	End If

	 'Set the PDF target file name
	oDataMedium.FileName = oFolder &amp;amp; "\" &amp;amp; modelname &amp;amp; ".pdf"
	
	&lt;STRONG&gt;'Publish document
	oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
	
	thisapplication.Documents.Open("[MACHINE DRAWING FILEPATH]" &amp;amp; modelname &amp;amp; ".dwg")
	ThisApplication.CommandManager.ControlDefinitions.Item("VaultCheckinTop").Execute2(False)&lt;/STRONG&gt;

Else
	Logger.Debug("saved?: " &amp;amp; saved)
	Exit Sub

End If

saved = False




&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Nov 2019 14:50:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-running-every-time-the-file-is-opened/m-p/9152762#M103172</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-11-18T14:50:12Z</dc:date>
    </item>
    <item>
      <title>Re: Rule running every time the file is opened</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-running-every-time-the-file-is-opened/m-p/9153016#M103175</link>
      <description>&lt;P&gt;Public Sub main()&lt;BR /&gt;If ThisDocument.FileSaveCounter = 0 Then&lt;BR /&gt;' skip the rule&lt;BR /&gt;End If&lt;BR /&gt;End Sub&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 16:14:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-running-every-time-the-file-is-opened/m-p/9153016#M103175</guid>
      <dc:creator>bradeneuropeArthur</dc:creator>
      <dc:date>2019-11-18T16:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: Rule running every time the file is opened</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-running-every-time-the-file-is-opened/m-p/9153077#M103176</link>
      <description>&lt;P&gt;This idea is great, thank you! I'm just wondering whether you knew of a way to implement this via iLogic? It doesn't seem to recognise .FileSaveCounter unfortunately.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 16:37:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-running-every-time-the-file-is-opened/m-p/9153077#M103176</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-11-18T16:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: Rule running every time the file is opened</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-running-every-time-the-file-is-opened/m-p/9153594#M103181</link>
      <description>&lt;PRE&gt;&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;doc&lt;/SPAN&gt; = &lt;SPAN&gt;ThisDoc&lt;/SPAN&gt;.&lt;SPAN&gt;Document&lt;/SPAN&gt;
&lt;SPAN&gt;MsgBox&lt;/SPAN&gt; (&lt;SPAN&gt;doc&lt;/SPAN&gt;.&lt;SPAN&gt;FileSaveCounter&lt;/SPAN&gt;)
&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;doc&lt;/SPAN&gt;.&lt;SPAN&gt;FileSaveCounter&lt;/SPAN&gt; = 0 &lt;SPAN&gt;Then&lt;/SPAN&gt;
	
	&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;If&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Savecounter.PNG" style="width: 286px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/699151i5B4FF442D7DCA5BB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Savecounter.PNG" alt="Savecounter.PNG" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 20:39:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-running-every-time-the-file-is-opened/m-p/9153594#M103181</guid>
      <dc:creator>bradeneuropeArthur</dc:creator>
      <dc:date>2019-11-18T20:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: Rule running every time the file is opened</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-running-every-time-the-file-is-opened/m-p/9154431#M103199</link>
      <description>&lt;P&gt;That looks like it works! Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Nov 2019 09:24:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-running-every-time-the-file-is-opened/m-p/9154431#M103199</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-11-19T09:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Rule running every time the file is opened</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-running-every-time-the-file-is-opened/m-p/9156772#M103258</link>
      <description>&lt;P&gt;Hey, I had a follow-up question if possible. I understand that .FileSaveCounter is a read-only file but the code you supplied says that as long as the value of .FileSaveCounter is 0, I can't perform the rest of my code. I can't flip it the other way because my file save counter is never 0. Curently it's at 33 or 34, something like that. Do you know a way to edit the code you supplied or perhaps have the counter reset to 0 at the beginning of the code? Here's my bit so far, thank you for your help.&lt;/P&gt;&lt;PRE&gt;Public Sub Main()
Dim doc = ThisDoc.Document

doc.FileSaveCount = 0
MsgBox(doc.FileSaveCounter)

If doc.FileSaveCounter = 0 Then
	
	
	Dim modelname As String
	Dim odoc As Document


	iLogicForm.Show("Save Drawing")

	modelname = iProperties.Value("Summary", "Title")

	If saved = True Then
		ThisDoc.Document.saveasinventordwg("[MACHINE DRAWING FILEPATH]" &amp;amp; modelname &amp;amp; ".dwg", True)
	
		oFileName = ThisDoc.FileName(False) 'without extension
		oRevNum = iProperties.Value("Project", "Revision Number")
		oPDFAddIn = ThisApplication.ApplicationAddIns.ItemById("{0AC6FD96-2F4D-42CE-8BE0-8AEA580399E4}")
		oDocument = ThisApplication.ActiveDocument
		oContext = ThisApplication.TransientObjects.CreateTranslationContext
		oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
		oOptions = ThisApplication.TransientObjects.CreateNameValueMap
		oDataMedium = ThisApplication.TransientObjects.CreateDataMedium

		oOptions.Value("All_Color_AS_Black") = 1
		oOptions.Value("Remove_Line_Weights") = 1
		oOptions.Value("Vector_Resolution") = 400
		oOptions.Value("Sheet_Range") = Inventor.PrintRangeEnum.kPrintAllSheets

		'get PDF target folder path
		oFolder = "[PDF DRAWING FILEPATH]"

		'Check for the PDF folder and create it if it does not exist
		If Not System.IO.Directory.Exists(oFolder) Then
	   		System.IO.Directory.CreateDirectory(oFolder)
		End If

		'Set the PDF target file name
		oDataMedium.FileName = oFolder &amp;amp; "\" &amp;amp; modelname &amp;amp; ".pdf"
	
		'Publish document
		oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
	
		ThisApplication.Documents.Open("[MACHINE DRAWING FILEPATH]" &amp;amp; modelname &amp;amp; ".dwg")
		ThisApplication.CommandManager.ControlDefinitions.Item("VaultCheckinTop").Execute2(False)

	Else
		Logger.Debug("saved?: " &amp;amp; saved)
		Exit Sub

	End If

	saved = False

End If
End Sub




&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Nov 2019 09:19:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-running-every-time-the-file-is-opened/m-p/9156772#M103258</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-11-20T09:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: Rule running every time the file is opened</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-running-every-time-the-file-is-opened/m-p/9157332#M103268</link>
      <description>&lt;P&gt;What do you exactly mean with the first time than?&lt;/P&gt;&lt;P&gt;Can this also be the first time that the rule has not run for this file?&lt;/P&gt;&lt;P&gt;Then I normally create a custom prop as Boolean =&amp;nbsp; false.&lt;/P&gt;&lt;P&gt;I read this and take a look if the rule has run once.&lt;/P&gt;&lt;P&gt;When the rule is fired I write the Boolean = true to that Custom Property.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 13:47:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-ilogic/rule-running-every-time-the-file-is-opened/m-p/9157332#M103268</guid>
      <dc:creator>bradeneuropeArthur</dc:creator>
      <dc:date>2019-11-20T13:47:41Z</dc:date>
    </item>
  </channel>
</rss>

