Old 09-21-2011, 01:42 PM   #1
Veto
Human being with feelings
 
Join Date: Aug 2010
Posts: 140
Default -----

-----

Last edited by Veto; 05-28-2018 at 09:10 AM.
Veto is offline   Reply With Quote
Old 09-21-2011, 03:11 PM   #2
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by Veto View Post
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...
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 02:30 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.