Know if autosave is running

Hi,

How can I control if Rhino’s automatic file saving mechanism is running on RhinoCommon? On RhinoDotNet I used “RhUtil.RhinoApp( ).AppSettings( ).FileSettings( ).m_autosave”, but I don’t find any similar boolean variable. I need to make difference between autosave from Rhino and save from user.

Thanks.

Dim autosave= Rhino.ApplicationSettings.FileSettings.AutoSaveEnabled.ToString
MsgBox(autosave)

here you can find all command for FileSettings and what it does.

Cheers.

Hi Jordy

Thanks, but I want to know if Rhino is saving automaticly the file, or the user is saving the file. In RhinoDoNet “m_autosave” is true if Rhino is saving, and false if user is saving. In RhinoCommon, “AutoSaveEnabled” is true if Rhino’s automatic file saving mechanism is enabled, so if user save the file, could be true.

I know to check if the file is saved by the user. is that enough for you or do you need to know when its autosaved?

Yes, I need to know when it is autosaved because I want to write different things in the document, depending if user saves, or Rhino saves.

Im testing a bit if I can get it to work. Got the idea in my head :slight_smile:

Cant get it to work. Ill try to explain.
I’m adding a AddHandler Rhino.RhinoDoc.EndSaveDocument, AddressOf SaveDocument in OnLoad

Private Sub SaveDocument(ByVal sender As Object, ByVal e As Rhino.DocumentSaveEventArgs)

        Dim App_Path = Rhino.RhinoDoc.ActiveDoc.Path

        If App_Path <> "" Then
            Dim saved As Date = System.IO.File.GetLastWriteTime(App_Path)
            Dim datenow As Date = Now
            Dim result = DateTime.Compare(saved, datenow.AddSeconds(-2))

            If result < 0 Then
                MsgBox("Autosave")

            ElseIf result = 0 Then
                MsgBox("User")

            Else
                MsgBox("User")
            End If

        End If

    End Sub

What it should do is check the date of the file, compare it with Date.Now. If it is less then 2 seconds difference. Say its user. Else Autosave.

But it only works if you save 2 times after eachother fast because I guess EndSaveDocument is used just before it “Saves” the file. :frowning:

Thanks for your help. I only wanted to know if there was any variable that indicates if atusave is running. But it seems on RhinoCommon doesn’t exists. I finally solved it checking the most recent command. If the most recent command is “Save”, I know user is saving.

Good thinking :).
Can you show me how you check what is the last runned command?

Here you are:

bool autoSave = false;
int numCommands;

numCommands = Rhino.Commands.Command.GetMostRecentCommands( ).Length;

if ( ( numCommands > 0 && Rhino.Commands.Command.GetMostRecentCommands( )[ numCommands - 1 ].DisplayString.Equals( "Autosave" ) ) || !Rhino.Commands.Command.InCommand( ) )
        autoSave = true;

There are two possibilities:

  1. File can be autosaved with command “_Autosave” (that’s controlled in the first part of the “if”).

  2. In the second part, I use “Rhino.Commands.Command.InCommand( )” because when Rhino autosave automatically, does not run any command, but if InCommand( ) is false, and I am writing the file, I know Rhino is autosaving.

InCommand( ) indicates if Rhino is currently running a command.

Really? What would you write differently, and why?

To my knowledge, there is no flag in Rhino that indicates whether or not Rhino is in the middle of an autosave operation.

I guess I need to know more about what you are doing.

Hi Dale,

I need it because user is working with some temporal geometries that I don’t write in the file. When user saves I delete these geometries. He knows that when he saves, these temporal geometries will disappear. But, if suddenly Rhino autosaves and the user is working with these geometries, it will dissapear too. I have to control this, deleting the geometries only when user saves.

I thought that on RhinoDoNet m_autosave indicates if Rhino is autosaving, but I think I was wrong, indicates if Rhino autosave is enable, like AutoSaveEnabled on RhinoCommon. I started the migration from RhinoDotNet to RhinoCommon just in that moment and I didn’t test it well.

Anyway, I think I have solved it doing what I explained on my last post.