Rule running every time the file is opened

Rule running every time the file is opened

Anonymous
Not applicable
964 Views
8 Replies
Message 1 of 9

Rule running every time the file is opened

Anonymous
Not applicable

Hi guys,

 

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?

 

Thanks

0 Likes
Accepted solutions (1)
965 Views
8 Replies
Replies (8)
Message 2 of 9

bradeneuropeArthur
Mentor
Mentor

could you share your code, so we can complete the code for you?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 9

Anonymous
Not applicable

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.

 

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]" & modelname & ".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 & "\" & modelname & ".pdf"
	
	'Publish document
	oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
	
	thisapplication.Documents.Open("[MACHINE DRAWING FILEPATH]" & modelname & ".dwg")
	ThisApplication.CommandManager.ControlDefinitions.Item("VaultCheckinTop").Execute2(False)

Else
	Logger.Debug("saved?: " & saved)
	Exit Sub

End If

saved = False




0 Likes
Message 4 of 9

bradeneuropeArthur
Mentor
Mentor

Public Sub main()
If ThisDocument.FileSaveCounter = 0 Then
' skip the rule
End If
End Sub

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 9

Anonymous
Not applicable

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.

0 Likes
Message 6 of 9

bradeneuropeArthur
Mentor
Mentor
Accepted solution
Dim doc = ThisDoc.Document
MsgBox (doc.FileSaveCounter)
If doc.FileSaveCounter = 0 Then
	
	End If

Savecounter.PNG 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 7 of 9

Anonymous
Not applicable

That looks like it works! Thank you!

0 Likes
Message 8 of 9

Anonymous
Not applicable

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.

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]" & modelname & ".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 & "\" & modelname & ".pdf"
	
		'Publish document
		oPDFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)
	
		ThisApplication.Documents.Open("[MACHINE DRAWING FILEPATH]" & modelname & ".dwg")
		ThisApplication.CommandManager.ControlDefinitions.Item("VaultCheckinTop").Execute2(False)

	Else
		Logger.Debug("saved?: " & saved)
		Exit Sub

	End If

	saved = False

End If
End Sub




0 Likes
Message 9 of 9

bradeneuropeArthur
Mentor
Mentor

What do you exactly mean with the first time than?

Can this also be the first time that the rule has not run for this file?

Then I normally create a custom prop as Boolean =  false.

I read this and take a look if the rule has run once.

When the rule is fired I write the Boolean = true to that Custom Property.

 

Regards,

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature