My Goal is to have 4 dropdown lists of shapekeys in a 3D view panel, allow the user to select 1 shapekey in each dropdown, and then reference those user-selected shapekeys in scripting that modifies their values based on relative camera position. They should dynamically update anytime the user changes the shapekeys.
I want it to operate like this:
To that end, I'm trying to create a dropdown using an enum: bpy.context.active_object.data.shape_keys.key_blocks.items()
I'd ideally like to place it inside a row.prop() I've defined, but for testing purposes I've tried placing it inside a layout.prop() and nothing populates in the panel. Can someone help me understand what I'm doing wrong?
Here's a look at the raw code: (Disclaimer: I'm a newbie Blender Python programmer, and there is a lot of code below that is redundant and for experimentation only)
bl_info = {
"Cam-Shape-Matic" : "CamShpMtc",
"category": "3D View",
"author": "BeyondDev",
"blender": (2, 8, 0),
"version": (0, 0, 1),
"category": "Object",
"description": "Drive Shapekeys on Objects based on Relative Camera Angle.",
"doc_url": "",
"tracker_url": "",
}
import bpy
import mathutils
class CamShapeMaticPanel(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'CamShpMtc'
bl_label = "CamShapeMatic"
bl_idname = "camshapematic.panel"
shapekey_enum : bpy.props.EnumProperty(
name ="",
description= "Select a shapekey",
items = bpy.context.active_object.data.shape_keys.key_blocks.items()
)
def draw(self, context):
layout = self.layout
layout.prop(self, "shapekey_enum")
box = layout.box()
col = box.column(align=True)
row = col.row(align=True)
row.label(text='Select Camera Angle Shapekeys')
scene = context.scene
row = col.row(align=True)
row.scale_y = 1.1
row.prop(scene, "camera")
obj = bpy.context.active_object
shape_keys = obj.data.shape_keys
active_key = obj.active_shape_key
active_index = obj.active_shape_key_index
shapeKeys = bpy.context.active_object.data.shape_keys.key_blocks
row = col.row(align=True)
row.scale_y = 1.1
#dropdown = row.template_list(align=True)
row.prop(self, "shapekey_enum")#, icon='SHAPEKEY_DATA', text='Test')
row = col.row(align=True)
row.scale_y = 1.1
row.prop(obj, 'active_shape_key', icon='SHAPEKEY_DATA', text='Up')
row = col.row(align=True)
row.scale_y = 1.1
row.prop(obj, 'active_shape_key', icon='SHAPEKEY_DATA', text='Down')
row = col.row(align=True)
row.scale_y = 1.1
row.prop(obj, 'active_shape_key', icon='SHAPEKEY_DATA', text='Left')
row = col.row(align=True)
row.scale_y = 1.1
row.prop(obj, 'active_shape_key', icon='SHAPEKEY_DATA', text='Right')
col.separator()
def register():
bpy.utils.register_class(CamShapeMaticPanel)
bpy.utils.register_class(DriveShapekey)
print('CamShapeMatic Addon Loaded')
def unregister():
bpy.utils.unregister_class(DriveShapekey)
bpy.utils.unregister_class(CamShapeMaticPanel)
#if __name__ == "__main__":
# register()
register()
obj_key = [k for k in bpy.data.shape_keys if k.user.name == obj.name][0]
furthermore if you use an enum property you'll still want to use a dynamic enum with several potential updates in the event someone modifies the keys outside your panel. I think a more robust description of your overall goal may be useful for people to offer aid. $\endgroup$