How to store user-defined data between Python scripts calls?


#1

Hello,
I made a few custom buttons that launch Python scripts by running for example, the following command:

_-RunPythonScript (Button_Load.py)

Some of these scripts would need to save some data (points, curves, text, etc) within the Rhino project (or document, I’m not entirely sure of the vocabulary here) so these data are available for the next script called.

How would you save for example a simple string variable so it is accessible for the next Python script? Could this data be automatically saved when saving the project as a 3dm file? That would be useful in case of crash at some step of the processing…

Thanks,

Bruno


#2

Hi Bruno,

take a look at scriptcontext.sticky which is a dictionary to store such information. There is an example named “sticky” in the python editors help section under samples.

Well in this case the sticky dictionary would get cleared, but you can write your data to an external temp file during script runs (might be slow with a lot of data).

You might take a look into rs.SetDocumentData and rs.GetDocumentData for saving and restoring strings, this data is saved with the document.


#3

Thanks, that’s exactly what I was looking for!

Bruno