0
$\begingroup$

Edit: I think I have found what I was looking for bpy.app.handlers.load_post, but will leave it open for maybe better suggestions.

I have a class variable that is stored in bpy.types.Scene.my_class, which I access with context.scene.my_class.

The problem I am having is that I need this class to be deleted and recreated when the user opens another .blend file from within Blender. The only way I can think of is to store path + file_name to the current .blend and check it before running the rest of my script to decide if my_class needs to be refreshed.

$\endgroup$
2
  • $\begingroup$ Is it a property or some "monkey patch" arrangement like bpy.types.Scene.foo = 2 ? $\endgroup$
    – batFINGER
    Apr 6, 2021 at 8:08
  • $\begingroup$ @batFINGER It is a monkey patch for sure, holds a custom class with internal data (numpy arrays, etc..) $\endgroup$
    – VSB
    Apr 6, 2021 at 12:36

1 Answer 1

0
$\begingroup$

Using a handler to remove my_class:

from bpy.app.handlers import persistent

@persistent
def handler_new_scene(scene):
    del bpy.types.Scene.my_class

I think del scene.my_class will work also, or scene.my_class = None if still need to have the attribute.

In the register function I add my function to the load_pre handler, which will run before a new scene is loaded:

bpy.app.handlers.load_pre.append(handler_new_scene)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .