iLogic code running every 15 minutes or every 100 actions

iLogic code running every 15 minutes or every 100 actions

francesco.dinh
Advocate Advocate
2,798 Views
7 Replies
Message 1 of 8

iLogic code running every 15 minutes or every 100 actions

francesco.dinh
Advocate
Advocate

I'm trying to write a little autosave script. Despite all pros/cons for this idea, I'd like to know how to make it work.

One little advice was given here, but it doesn't seem to work for me.

 

By tweaking the code a bit, it looks like this:

 

If AutoSaveTrigger >= 100 Then
	AutoSaveTrigger = 0
	savefile = MessageBox.Show("Do you want to save?", "Autosave", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
	If savefile = vbYes Then
		ThisDoc.Save
	End If
Else
	AutoSaveTrigger += 1
End If

and I assign it to parameter change. However, it doesn't do anything.

 

I think it has something to do with AutoSaveTrigger, but I can't put my finger on it. I dont' know if Inventor "forgets" this parameter value once the rule is fired.

 

Bonus question: would it be possible to do so that the rule runs every 15min instead of every 100 actions?

 

Thanks!

 

Edit: just a few thoughts from another thread:

- I know that there is a "save reminder", but that's not what I'm looking for

- I started with iLogic because I want this event to activate periodically, like 100 actions after or 15 min after the last save. I'm willing to switch to VB.net if it adds any benefit.

- If done in iLogic, I'd add the code to the template doc so that it's used in all parts, assemblies and drawings from now on.

0 Likes
Accepted solutions (1)
2,799 Views
7 Replies
Replies (7)
Message 2 of 8

Owner2229
Advisor
Advisor

Just use this:

 

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 AST >= 15 Then '15 minutes
			AST = 0
			Dim SF As DialogResult = MessageBox.Show("Do you want to save?", "Autosave", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
			If SF = vbYes Then
				ThisDoc.Save()
			End If
		Else
			AST += 1
		End If
		System.Threading.Thread.Sleep(60000) '1 minute = 60000 ms
	End While
End Sub

 

If you want it to be 100 actions instead of 15 just do the maths. It'll be 100 and  9000

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 3 of 8

francesco.dinh
Advocate
Advocate

Whoa, thanks! Sorry if I haven't replied all day, I'll try it right along when I'll be back to my office. Thanks a bunch!

0 Likes
Message 4 of 8

Owner2229
Advisor
Advisor
Accepted solution

Here's the code with a document check to prevent an attempt to save closed document.

It will keep reseting until you (re)open new(another) document.

 

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 '15 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
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 5 of 8

nkirton
Enthusiast
Enthusiast

Thank you so much! This works great!

Is there a way to have the window that pops up force a user to make a choice? I see that I can miss-click and the window disappears.

Nathan Kirton


If what I said helped you out, please use the ACCEPT AS SOLUTION or KUDOS buttons.


"I don't know why it doesn't work. It fit in the model!"

0 Likes
Message 6 of 8

josef_kostecký
Participant
Participant

Please help,

by me run rule after close document or inventor fall down.

0 Likes
Message 7 of 8

Anonymous
Not applicable

How to exclude the Thread1 "Autosave" if I regret to use.

0 Likes
Message 8 of 8

Aadithya01
Advisor
Advisor

Hi @Owner2229 ,

 

I tried this code in Inventor 2023 .. With my Inventor Session kept open and if I dont attend the computer for a while.. Multiple Autosave dialogue box pop-ups appears where when choosing the yes or no option is crashing Inventor ..  

 

Also what does this Else logic do

        Else
            AST += 1

 

Could you kindly help me to resolve this issue.

0 Likes