I am trying to create an add-on that has a feature that allows the user to select up to 5 objects that exist in their scene. To do this I've created 5 enumerators, however, I'm struggling when it comes to the "items" parameter. So far I've figured out that an object is stored in bpy.data.objects[""].name, but I can't find the location of the list/dictionary for all existing objects in the scene in order to reference it in the code.
Is this possible to do? If so how can I code the enumerators to use the list/dictionary of existing objects?
Side Note: I plan on doing this with the list of existing materials within the scene as well, so would it be the same deal as the objects?
I would really appreciate it if somebody could help me figure this out, thanks!
My code:
import bpy
class Object_Enums(bpy.types.PropertyGroup):
enum1 : bpy.props.EnumProperty(
name= "#1",
description= "sample text",
items= [
]
)
enum2 : bpy.props.EnumProperty(
name= "#2",
description= "sample text",
items= [
]
)
enum3 : bpy.props.EnumProperty(
name= "#3",
description= "sample text",
items= [
]
)
enum4 : bpy.props.EnumProperty(
name= "#4",
description= "sample text",
items= [
]
)
enum5 : bpy.props.EnumProperty(
name= "#5",
description= "sample text",
items= [
]
)
class ADDONNAME_PT_main_panel(bpy.types.Panel):
bl_label = "ADDONNAME"
bl_idname = "ADDONNAME_PT_main_panel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "ADDONNAME"
def draw(self, context):
layout = self.layout
scene = context.scene
mytool = scene.my_tool
layout.prop(mytool, "enum1")
layout.prop(mytool, "enum2")
layout.prop(mytool, "enum3")
layout.prop(mytool, "enum4")
layout.prop(mytool, "enum5")
row = layout.row()
class ADDONNAME_OT_my_op(bpy.types.Operator):
bl_label = "Operator"
bl_idname = "addonname.myop_operator"
def execute(self, context):
return {'FINISHED'}
classes = [Object_Enums, ADDONNAME_PT_main_panel, ADDONNAME_OT_my_op]
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.my_tool = bpy.props.PointerProperty(type= Object_Enums)
def unregister():
for cls in classes:
bpy.utils.unregister_class(cls)
del bpy.types.Scene.my_tool
if __name__ == "__main__":
register()