I want to save add-on settings and load it in next blender session. I mean I want Blender remember the last checkbox state. this is my code, but when I run it, checkbox will disappear:
bl_info = {
"name": "Persistent Checkbox Addon",
"blender": (2, 80, 0),
"category": "3D View",
}
import bpy
class AddonPreferences(bpy.types.AddonPreferences):
bl_idname = __name__
my_checkbox: bpy.props.BoolProperty(
name="My Checkbox",
description="Stores the state of the checkbox",
default=False
)
def draw(self, context):
layout = self.layout
layout.prop(self, "my_checkbox")
class SimpleCheckboxPanel(bpy.types.Panel):
bl_label = "Persistent Checkbox"
bl_idname = "VIEW3D_PT_persistent_checkbox"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "New Tab"
def draw(self, context):
layout = self.layout
prefs = context.preferences.addons[__name__].preferences
layout.prop(prefs, "my_checkbox", text="Enable Option")
def register():
bpy.utils.register_class(AddonPreferences)
bpy.utils.register_class(SimpleCheckboxPanel)
def unregister():
bpy.utils.unregister_class(AddonPreferences)
bpy.utils.unregister_class(SimpleCheckboxPanel)
if __name__ == "__main__":
register()