- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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 Ifand 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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- - - - - - - - - - - - - - -
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- - - - - - - - - - - - - - -
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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!"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.