I want to save a dict of random information to the scene, per .blend file, the dict updates fine but on reload it is back to its defaults.
bl_info = {
"name": "Test",
"author": "Test",
"version": (1, 0),
"blender": (2, 80, 0),
"description": "",
"category": "3D View"}
import bpy
from bpy.app.handlers import persistent
region_3d_settings = (
"view_location",
"view_distance",
"view_rotation",
"view_perspective"
)
class Test_Variables(bpy.types.PropertyGroup):
startup_settings = {"clip" : {"start" : 0.01, "end" : 100},
"viewport" : {},
}
@persistent
def pre_save(scene):
self_vars = bpy.context.scene.test_vars
for a in bpy.context.screen.areas:
if a.type == 'VIEW_3D':
for setting in region_3d_settings:
self_vars.startup_settings["viewport"][setting] = getattr(a.spaces[0].region_3d, setting)
for s in a.spaces:
if s.type == 'VIEW_3D':
self_vars.startup_settings["clip"]["start"] = s.clip_start
self_vars.startup_settings["clip"]["end"] = s.clip_end
break
classes = (
Test_Variables,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.test_vars = bpy.props.PointerProperty(type = Test_Variables)
bpy.app.handlers.save_pre.append(pre_save)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
del bpy.types.Scene.test_vars
if pre_save.__name__ in [hand.__name__ for hand in bpy.app.handlers.save_pre]:
bpy.app.handlers.save_pre.remove(pre_save)
if __name__ == "__main__":
register()