I am writing an addon for blender 2.8.
And I’d like to know if is possible to create a combobox (or dropdown), that has a number of items I’d like to update or change when click on a button?. I am not able to update the drawing of the combobox in the ui when the button is clicked.
Any advice or support?
This is my code:
import bpy
#from bpy.props import *
bl_info = {
"name": "combobox",
"description": "mio",
"author": "zebus3d",
"version": (0, 0, 1),
"blender": (2, 80, 0),
"location": "View3D",
"wiki_url": "",
"category": "3D View" }
def accionComboBox(self, context):
print(self.comboItems)
context.area.tag_redraw()
class myProperties(bpy.types.PropertyGroup):
if not hasattr(bpy.types.Scene, "my_items"):
comboItems = [ ("INTERIOR", "default value", "", 1), ("EXTERIOR", "example", "", 2), ("NONE", "None", "", 3) ]
else:
comboItems = bpy.types.Scene.my_items
comboBox = bpy.props.EnumProperty(
items=comboItems,
name="Scene Type",
description="Scene Type",
default="NONE",
update=accionComboBox
)
class ButtonClass(bpy.types.Operator):
bl_label = "Button"
bl_idname = "b.action"
bl_description = "My first button"
def execute(self, context):
bpy.types.Scene.my_items = [ ("INTERIOR", "new value", "", 1), ("EXTERIOR", "yes!", "", 2), ("NONE", "None", "", 3) ]
context.area.tag_redraw()
return {'FINISHED'}
class CustomPanel(bpy.types.Panel):
bl_label = "Generate"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "myComboBox"
def draw(self, context):
layout = self.layout
col = layout.column()
col.prop(context.scene.my_addon, "comboBox", text="")
col.operator("b.action", text="Update content")
def register():
bpy.utils.register_class(myProperties)
bpy.utils.register_class(ButtonClass)
bpy.utils.register_class(CustomPanel)
bpy.types.Scene.my_addon = bpy.props.PointerProperty(type=myProperties)
def unregister():
bpy.utils.unregister_class(myProperties)
bpy.utils.unregister_class(ButtonClass)
bpy.utils.unregister_class(CustomPanel)
del bpy.types.Scene.my_addon
del bpy.types.Scene.my_items
if __name__ == "__main__":
register()
Thanks.