I’m programming a Blender add-on.
I have a EnumProperty dropdown and a BoolProperty checkbox. When a particular EnumProperty value is selected from the dropdown, I want to disable the BoolProperty checkbox. Otherwise, the BoolProperty checkbox should be enabled.
How is this done? I haven’t been able to find an example. Thanks!
CoDEmanX
(CoDEmanX)
June 10, 2014, 6:01pm
2
import bpy
class HelloWorldPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Hello World Panel"
bl_idname = "OBJECT_PT_hello"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
def draw(self, context):
layout = self.layout
layout.prop(context.scene, "my_enum")
layout.prop(context.scene, "my_bool")
enum_items = (
('A', "Option A", ""),
('B', "Option B", ""),
)
def upd(self, context):
if self.my_enum == 'B':
self.my_bool = False
def register():
bpy.utils.register_class(HelloWorldPanel)
bpy.types.Scene.my_enum = bpy.props.EnumProperty(items=enum_items, update=upd)
bpy.types.Scene.my_bool = bpy.props.BoolProperty()
def unregister():
bpy.utils.unregister_class(HelloWorldPanel)
if __name__ == "__main__":
register()
Tick the checkbox, then select Option B from dropdown - the checkbox will be unticked.
Thanks, CoDEmanX – that’s very, very close to what I would like to do. How would I disable the checkbox instead of unticking it?
CoDEmanX
(CoDEmanX)
June 11, 2014, 1:25am
4
That works pretty different, since it’s not on the data level but layout level:
import bpy
class HelloWorldPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Hello World Panel"
bl_idname = "OBJECT_PT_hello"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
def draw(self, context):
layout = self.layout
scene = context.scene
layout.prop(scene, "my_enum")
col = layout.column()
col.enabled = scene.my_enum != 'B'
col.prop(context.scene, "my_bool")
enum_items = (
('A', "Option A", ""),
('B', "Option B", ""),
)
def register():
bpy.utils.register_class(HelloWorldPanel)
bpy.types.Scene.my_enum = bpy.props.EnumProperty(items=enum_items)
bpy.types.Scene.my_bool = bpy.props.BoolProperty()
def unregister():
bpy.utils.unregister_class(HelloWorldPanel)
del bpy.types.Scene.my_enum
del bpy.types.Scene.my_bool
if __name__ == "__main__":
register()
Thanks, CoDEmanX – that’s exactly what I needed!