I’m looking for an example of a script showing how to create an object list… But of a specific kind. There are two kinds of lists in blender :
Let’s look at the properties panel (n key).
in the transform block there is a list for rotation mode (XYZ Euler, etc…). I know how to do with that.
in the view block, there is a list under “Lock to Object”. Maybe “list” is not the right word, but this is what I’m looking for.
In my “list” I want the cameras of the scene.
prop_search(scene, “my_search”, scene, “cameras”) just fails, and
prop_search(scene, “my_search”, bpy.data, “cameras”) returns all the cameras of all scenes.
do you know how to do ?
I realized that in the camera list (returned by bpy.data, “cameras”), it’s the camera names, not the object names. And of course, I want the object name.
Do you know if instead of “cameras”, “objects”, “armatures” or whatever, it would be possible to put the result of such a “filter” ?
cameras=[]
for obj in scene.objects
if obj.type==‘CAMERA’:
cameras.extend([obj])
oh sorry, I tried very hard, I promise, but here, it’s too difficult for me. I never used the collection property, and despite searching the internet, I don’t see…
in the register section :
bpy.types.Scene.mycameras = bpy.props.CollectionProperty(???)
in the draw section :
prop_search(scene, “my_search”, bpy.data, “mycameras”)
in a particular section ? :
mycameras = [c for c in scene.objects if c.type == ‘CAMERA’]
I tried different things but I won’t succeed by chance.
Would you give me a little bit more details ? Thanks
import bpy
class SimpleOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.simple_operator"
bl_label = "Simple Object Operator"
cam = bpy.props.StringProperty(default="", options={'SKIP_SAVE'})
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
print("CAMERA", self.cam)
cam = context.scene.objects.get(self.cam)
context.scene.camera = cam
return {'FINISHED'}
class SimpleCustomMenu(bpy.types.Menu):
bl_label = "Simple Custom Menu"
bl_idname = "OBJECT_MT_simple_custom_menu"
def draw(self, context):
layout = self.layout
cams = [c for c in context.scene.objects if c.type == 'CAMERA']
print(cams)
for c in cams:
op = layout.operator("object.simple_operator",text=c.name)
op.cam = c.name
def register():
bpy.utils.register_class(SimpleCustomMenu)
bpy.utils.register_class(SimpleOperator)
def unregister():
bpy.utils.unregister_class(SimpleCustomMenu)
bpy.utils.register_class(SimpleOperator)
if __name__ == "__main__":
register()
# The menu can also be called from scripts
bpy.ops.wm.call_menu(name=SimpleCustomMenu.bl_idname)
I know the menu layout, but it’s not my need. I want to choose a camera, not to make it active. My script calculates vertices that are in the field of the camera. I can choose “Active camera” with a check box or another camera in a list if the box is unchecked. Until now, I used a operator_menu_enum that worked fine. But for interface consistency I would prefer a prop_search as you suggested. You spoke about CollectionProperty to customize the “cameras” list. I just wanted to know how you do that. I don’t understand collectionproperty…