Odd autosave in Python


#1

I am working on a script and when I edit something, then run it, terminate it, and close Rhino I do NOT get the answer if I want to save the edited script, BUT it is saved… Rhino does ask if I want to save the Rhino file, but not the edited python script…

So what is going on? It should not do that.


#2

As Steve explained it to me once, in order to run the Python script from the editor, it has to be saved first (this is probably because running the script is simply running the .py file). So when you run the script, it is already saved.

This is only a PITA if you are making temp changes to the script and don’t want to save them, you need to remember to undo back to where you were (hard) or what I do now: systematically save the script under another name before modifying it (as in scriptname-dev1.py) and do all my development work on multiple incremental saves; delete all the unwanted versions later.

–Mitch


#3

Ahh… I don’t think that’s a good sollution… As nothing else in Rhino overwrites the original file with out waring the user.
I strongly think they should rather make a “filename”-temp.py file and run that, then delete it after it is ran. I presume that is how it can run an unsaved script…?

I have the habit of saving a script prior to running it, so that is probably why I have not ran into this situation before.

Because right now this feels like a development hack rather than a final release sollution.


(Menno Deij - van Rijswijk) #4

IMHO it is proper behavior of any code-executing program (Visual Studio comes to mind) to silently save source files prior to running the code. Like you said, you already have the habit so it makes sense I guess.


(Pascal Golay) #5

Yep, I hate this. It’s like the Mac saving rhino files all the time, what a mess. I kind of sorted that out with a OSX prefernces but I am not convinced it is working as it should.

-Pascal


(Steve Baer) #6

I have some ideas on how to improve this in a future version of Rhino. Editors like pyCharm keep local file history for scripts which is great for going back and seeing what you’ve changed over time (pretty much a very light version control system.)


Python editor in Rhino could use some tweaking
#7

Personally I would prefer if it used a temp file instead, since that is how Rhino works.
I have messed up a few scripts because of the habit of opening a file, doing modifications, then saving it with another name… And some times I test run the script prior to saving, and then I have f@ked up the previous file. This is apparently such an old habit for me that it is hard to break. So anything that improves this is good.

And a warning prior to saving prior to running is the least it should do. And please add a " [ ] do not show warning again for this session" option would also help a lot…

So thanks for looking into this! That is much appreciated.


(Steve Baer) #8

Temp files can be a bit tricky when the scripts span multiple files. I’m not saying it can’t be done, but I’m definitely not going to run off and implement this for Rhino 5. Any change along this level is going to be in a future version of Rhino.


#9

OK.
But would a ‘scriptname’_temp_01.ru at script file location do the trick?
I would presume it is possible to check for a file with that name at location, and if so going for _02 or above. I check for files in Holomark2 now, and it seems pretty stable.


(Steve Baer) #10

There are subtle problems that I just don’t want to pollute V5 with.

  • A temp file must be created in the same directory as the main script so paths are set properly. If I don’t have rights to create a file in that directory, then I need to do something else
  • If the script imports a file and that file in turn also imports the original script, confusing problems will occur
  • If the script crashes Rhino (which is much easier in python than RhinoScript because I give you a whole lot of rope to hang yourself by), there will be a temp file that didn’t get cleaned up in that directory.
  • If you have multiple files open that you are writing for your script, you will run into problems if you don’t remember to save each file manually.

I’m sure there are others, but as you mentioned I need to go celebrate the new year :smiley:


#11

Obviously: You are the man for the job! :smiley:

Go enjoy!