I'm using a Python class static members properties in order to store the state of the addon I'm developing. It works fine and my Python class is brand new every time I start Blender. Problem is, if I do file->new or revert, that class is not created anew and still stores values that are relevant to the old file. Is there any way to achieve that?
1 Answer
$\begingroup$
$\endgroup$
1
A persistent onload handler
Code taken directly from Persistent Handler Example
import bpy
from bpy.app.handlers import persistent
@persistent
def load_handler(dummy):
print("Load Handler:", bpy.data.filepath)
bpy.app.handlers.load_post.append(load_handler)
Other things to consider re comment for revert and new is look at
bpy.data.is_dirty
for toggle from True
to False
. Wont matter if a clean file is reverted.
-
$\begingroup$ Thank you. So this will work in the load case. Not in file->new or revert cases. Nice to learn about handlers though. $\endgroup$– KiskitCommented Dec 9, 2019 at 9:29