I have a checkbox in my addon and I wonder how I can I execute or run some code when checking and unchecking it. I found this link but I tried following the given answer there (as shown below) but it is not working, nothing happens when I check/uncheck the checkbox.
This is my script:
bl_info = {
"name": "tester",
"description": "",
}
import bpy
import os
from bpy.props import (StringProperty,
BoolProperty,
IntProperty,
FloatProperty,
FloatVectorProperty,
EnumProperty,
PointerProperty,
)
from bpy.types import (Panel,
Operator,
AddonPreferences,
PropertyGroup,
)
class MySettings(PropertyGroup):
my_bool = BoolProperty(
name="Enable or Disable",
description="A bool property",
default = False
)
class UV_OT_my_panel(Panel):
bl_idname = "UV_OT_my_panel"
bl_label = "My Tool"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_category = "Tools"
def draw(self, context):
layout = self.layout
scene = context.scene
mytool = scene.my_tool
# display the properties
layout.prop(mytool, "my_bool", text="Bool Property")
layout.prop(mytool, "my_int", text="Integer Property")
layout.prop(mytool, "my_float", text="Float Property")
# check if bool property is enabled
if (mytool.my_bool == True):
print ("Property Enabled")
# bpy.data.objects['Cube'].hide = True
else:
print ("Property Disabled")
# bpy.data.objects['Cube'].hide = False
def register():
bpy.utils.register_module(__name__)
bpy.types.Scene.my_tool = PointerProperty(type=MySettings)
def unregister():
bpy.utils.unregister_module(__name__)
del bpy.types.Scene.my_tool
if __name__ == "__main__":
register()
os.system('cls')
def my_prop_callback(self, context):
if context.scene.my_prop:
#pass # do something here if user checks checkbox (but not uncheck, just as an example)
print('Enteredddddddddddddddddddddddddd')
if context.scene.mytool.my_bool == True:
bpy.data.objects['Cube'].hide = True
else:
bpy.data.objects['Cube'].hide = False
bpy.types.Scene.my_prop = bpy.props.BoolProperty(update=my_prop_callback)


