Hi again!
Well, after having a closer look, it does seem possible to save any Python object into an Itasca savefile : using 3DEC v7.00.146, I can save and restore variables, classes and their instances, and even modules!
Say you type this in your IPython console (demo class from Python documentation):
>>> import itasca as it
>>> class Dog:
... def __init__(self, name):
... self.name = name
... self.tricks = [] # creates a new empty list for each dog
... def add_trick(self, trick):
... self.tricks.append(trick)
...
>>> rosco = Dog('rosco')
>>> rosco.add_trick('bark')
>>> rosco.add_trick('steal bacon')
>>> rosco.tricks
('bark', 'steal bacon')
>>> import numpy as np
>>> it.add_save_variable('rosco')
>>> it.add_save_variable('Dog')
>>> it.add_save_variable('np')
>>> it.get_save_variables()
(b'rosco', b'Dog', b'np')
Now, in the 3DEC console : model save "demo_py_variables.3dsav"
.
If I open a new session of 3DEC, and make a model restore "demo_py_variables.3dsav"
command, I can then restore my Python variables through the common Python locals(), globals(), or vars() entries :
>>> import itasca as it
>>> it.get_save_variables()
(b'rosco', b'Dog', b'np')
>>> rosco = globals()['rosco']
>>> Dog = globals()['Dog']
>>> isinstance(rosco, Dog)
True
>>> rosco.tricks
('bark', 'steal bacon')
>>> np = globals()['np']
>>> np.arange(5)
array([0, 1, 2, 3, 4])
Still, I would keep the Python devs separately from the pure Itasca saves.
To me, it’s easier to keep an overview on your Python developments if you have separated scripts, rather than through exploration of the variables you would have stored directly within the Itasca saves.
Hey, just my opinion!
Good luck, and let us know if you could make your stuff work!