Inventor iLogic - Autosave tool - Checking if inventor is already running a process.

Inventor iLogic - Autosave tool - Checking if inventor is already running a process.

joe_love-gunn
Contributor Contributor
261 Views
2 Replies
Message 1 of 3

Inventor iLogic - Autosave tool - Checking if inventor is already running a process.

joe_love-gunn
Contributor
Contributor

I am currently creating a code that will prompt the user every few minutes to whether they want to save the document due to large project models making inventor unstable/crashing more regularly. Currently this code brings up a message box that will ask the user if they want to save (yes or no), If yes is selected then the currently open document will save. if not then the counter will restart and prompt again 15 minutes later. There are currently 2 more things I want to add but am struggling to work out how to implement them. the first is to make the message box prompt forced to the top until an option is selected. The other task I would like to implement is a check so that once it gets to 15 minutes before the message box appears the code checks to see if the inventor program is currently completing a process and only opens the message box after the process is completed. For example exporting a 20-page drawing as a DWG and when it gets to page 10 the 15 minutes are up so the save message box won't appear until all 20 pages are exported, or if a process is ongoing it will skip the code and reset the timer.

 

Sub Main()
	Dim Thread1 As New System.Threading.Thread(AddressOf AutoSave)
	Thread1.Start()
End Sub

Sub AutoSave()
	Dim AST As Integer = 0
	While True
		If ThisDoc IsNot Nothing Then
			If AST >= 15 Then '1 minutes
				AST = 0
				Dim SF As DialogResult = MessageBox.Show("Do you want to save?", "Autosave", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
				If SF = vbYes And ThisDoc IsNot Nothing Then
					ThisDoc.Save()
				End If
			Else
				AST += 1
			End If
		Else
			AST = 0
		End If
		System.Threading.Thread.Sleep(60000) '1 minute = 60000 ms
	End While
End Sub
0 Likes
262 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor

You can follow/subscribe to the events:

  • Inventor.ActiveDocument.DocumentEvents.OnSave
  • Inventor.ApplicationEvents.OnSaveDocument

When one of those events gets fired then you can reset the timer.

 

On the point of checking if Inventor is running.  You could use a property like this:

Public ReadOnly Property InventorIsRunning As Boolean
	Get
		Try
			Dim inventorApp = Marshal.GetActiveObject("Inventor.Application")
		Catch ex As Exception
			Return False
		End Try
		Return True
	End Get
End Property

But this all sound like you are creating a standalone application. I wonder why? If you create an addin for inventor then your tool would only run when Inventor is running. In that case you would not need to check if Invntor is running.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 3

joe_love-gunn
Contributor
Contributor

Hi @JelteDeJong, yes, so we are attempting to create this as a iLogic tool within inventor, I hadn't thought about using it as an add-in Program rather than an iLogic program but I will consider that. as this runs when inventor is running I don't necessarily want to check if inventor is running but more if inventor is already completing a command/task such as model/dwg export, so as to not hinder the currently running task but to complete the save once the task inventor is completing is completed.

As currently when exporting a multipage drawing file (as for our current project all drawings have to be exported on individual pages), if the timer maxes out during the export the program saves the current document then continues exporting the drawing, which in my mind could posses the chance to crash inventor more easily.

0 Likes