I have a bool property. I can save the state of the bool property in the startup file. And it will load in this state when you start Blender.
The problem is when i load a new blend file then this bool gets reset to its default status. Or to the state in which it gots saved to the blend file.
Both is not wanted behaviour. I want to keep the state in which it was saved in the startup file when i load a new file. It is a setting of my addon. It is a bit cumbersome to turn the checkbox on (or off) every time you load a new blend file.
Is there a way to prevent to load the status of the bool with loading a blend file? But just with the startup file?
Examplescript to test the problem. Run it in the scripting layout, turn on the checkbox in the properties sidebar and load a new blend file to see the problem:
import bpy
class MyData(bpy.types.PropertyGroup):
checkbox_bool = bpy.props.BoolProperty(name="A checkbox", description="Do this or that", default = False) # Our prop
class CheckboxpropPanel(bpy.types.Panel):
bl_label = "Checkbox prop"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
def draw(self, context):
layout = self.layout
scene = context.scene # Our data is in the current scene
layout.prop(scene.my_addon_data, "checkbox_bool") # Our checkbox
# Example useage of the bool.
if scene.my_addon_data.checkbox_bool:
layout.label(text="checkbox is on")
else:
col = layout.column(align=True)
col.label(text="checkbox is off")
def register():
bpy.utils.register_class(CheckboxpropPanel)
#Our data block
bpy.utils.register_class(MyData) # Our data block
bpy.types.Scene.my_addon_data = bpy.props.PointerProperty(type=MyData) # Bind reference of type of our data block to type Scene objects
def unregister():
del bpy.types.Scene.my_addon_data # Unregister our data block when unregister.
bpy.utils.unregister_class(MyData) # Our data block
bpy.utils.unregister_class(CheckboxpropPanel)
if __name__ == "__main__":
register()