Quote:
Originally Posted by Veto
Hi everybody,
according to this thread there is no way in ReaScript that a variable persists from one script to another and so saving/loading a file is unavoidable.
What im trying to achieve is to save some info (about selected notes) in a file with a specified name, load that file with another script (i.e. restore note selection) and remove that file on Reaper exit or os-shutdown.
Currently i do it this way:
save:
Code:
import tempfile
import pickle
TempPath=tempfile.gettempdir()
Name="ReaScript_SaveNoteSelection.txt"
file = open(TempPath+"\\"+Name,"wb")
pickle.dump(ListOfSelectedNotes,file)
load:
Code:
import tempfile
import pickle
TempPath=tempfile.gettempdir()
Name="ReaScript_SaveNoteSelection.txt"
ListOfSavedSelectedNotes=[]
try:
file = open(TempPath+"\\"+Name,"rb")
ListOfSavedSelectedNotes=pickle.load(file)
My questions would be:
1: noobish as i am im feeling a bit unsure here, am i doing this right? would there be a more straightfoward solution? How do SWS recall information for their "Restore saved ..." - actions?
2: how could i remove the file from the temp folder on shutdown or Reaper exit?
i would love to here your opinions on that matter
thanks
V
|
Assuming your data serialization and deserialization (ie the save and load of the data) processing is working, it should be ok how you are doing it now. For cleaning up the temp folder I suppose there's no other way with ReaScript than for you to write an action script that does the clean up and then add a custom action (macro) to Reaper that calls that script and then quits. (I would not necessarily recommend calling the Reaper Quit action directly from ReaScript code...)
This reminds me how useful and nice it'd be to have some way to register for callbacks to ReaScript in Reaper...OTOH, that might be a can of worms in terms of how much API there should be for that...