Typed Object selection dropdown

Hi forum,

I’m trying to add a dropdown list to select between cameras in my custom panel.
I can’t figure the best way.

I managed to have an equivalent but not very confortable with it.

        layout.prop_search(data = context.scene,
            property = 'camera',
            search_data = bpy.context.scene,
            search_property = 'objects',
            text = 'Select Object',
            icon = 'CAMERA_DATA')

Is there a better way out there?

Thanks

What’s the actual purpose of this? Can you use the scene camera property instead?

My goal here is to make multiple render of the same scene with multiple cameras and renderlayers configurations.
I can’t modify the active camera property, i have to store wich camera is applied on each renderlayer config (called MultiLayer).
I made a custom collection wich store the different configurations, showed with a template_list.
Then, when a property in a MultiLayer config is changed, I use the update parameter of the prop to update the Blender renderlayer’s structures.

I suppose to store the camera in my collection, I have to use a PointerProperty.
But I would like to have a box to select wich camera is applied on each MultiLayer.

This all architexture is for separate renderings for a video mapping show.

By searching in blender python sources, I can see it can be done with just using “layout.prop”, or “layout.prop_search”.
But I don’t know how to create a property wich can store only camera objects.

I managed to do it a better way but not optimal yet.

scene = context.scene
multilayers = scene.MultiLayers
multilayers_index = scene.MultiLayers_index
layout.prop_search(multilayers[multilayers_index], "camera_front", bpy.data, "cameras")

“camera_front” is a StringProperty() of my MultiLayers collection.
I would like to show only the current scene camera.

The way I see it, would to combine bpy.data.cameras and bpy.context.scene.objects.
Anyway to do that?

I finally get the way.

def getcameras(self, context):
    cameras = []
    for object in context.scene.objects:
        if object.type == "CAMERA":
            cameras.append(object)
    return [(cam.name, cam.name, cam.name) for cam in cameras]

class MultiLayerCollection(bpy.types.PropertyGroup):
    cam_front = EnumProperty(items = getcameras)

class MultiLayersCam(bpy.types.Panel):
    bl_label = "Multi Camera Layers"
    bl_idname = "MULTI_CAM_LAYERS"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = 'render_layer'
    def draw(self, context):
        layout = self.layout
        scene = context.scene
        render = scene.render
        multilayers = scene.MultiLayers
        multilayers_index = scene.MultiLayers_index
        layout.prop(multilayers[multilayers_index], "cam_front", text="Front Camera")

bpy.utils.register_class(MultiLayerCollection)
bpy.types.Scene.MultiLayers = bpy.props.CollectionProperty(type = MultiLayerCollection)
bpy.types.Scene.MultiLayers_index = IntProperty()