0
$\begingroup$

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?

$\endgroup$
1
$\begingroup$

A persistent onload handler

Application handlers.

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.

$\endgroup$
  • $\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$ – Kiskit Dec 9 '19 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.