Display a custom list in the UI

Hey,
I’m new to scripting and I’m trying to write a script that will do this:

  1. add the selected camera to a list
  2. display the list in the UI with the ability to select items from that list to remove them from the list.
  3. button to write the list to a text file

also I dont want the list to be sorted in any way other than order of selection.

I’m mainly stuck on the second step. I have NO idea on how to go about displaying a list in the UI…

I’m using blender 2.62
Any help would be appreciated!
Thanks

needs a bit of refinement, but this should get you started:



import bpy


def camlist_update(self,context):
    '''potentially useless function '''
    print(context.scene.camlist.cameras[:])

class CAMLIST_OT_add_selected_camera(bpy.types.Operator):
    bl_idname = 'camlist.add_selected'
    bl_label = 'Add Selected Camera to Camlist'
    @classmethod
    def poll(self,context):
        return context.active_object and context.active_object.type == 'CAMERA'
    def execute(self,context):
        camlist = context.scene.camlist
        new_camlist_item = camlist.cameras.add()
        new_camlist_item.name = context.active_object.name
        camlist.cameras_i += 1
        return {'FINISHED'}
class CAMLIST_OT_remove(bpy.types.Operator):
    bl_idname = 'camlist.remove'
    bl_label = 'Remove Camera from Camlist'
    bl_options = {'INTERNAL'}
    @classmethod
    def poll(self,context):
        return context.scene.camlist.cameras_i > -1
    def execute(self,context):
        camlist = context.scene.camlist
        camlist.cameras.remove(camlist.cameras_i)
        camlist.cameras_i -= 1
        return {'FINISHED'}


class cam(bpy.types.PropertyGroup):
    name = bpy.props.StringProperty()


class camlist_property(bpy.types.PropertyGroup):
    cameras = bpy.props.CollectionProperty(type=cam)
    cameras_i = bpy.props.IntProperty(min=-1,default=-1,update=camlist_update)


class CAMLIST_PT_camlist_panel(bpy.types.Panel):
    bl_label = "Camera List"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = 'scene'
    def draw(self,context):
        camlist = context.scene.camlist
        split = self.layout.split(percentage=0.8)
        col1,col2 = split.column(),split.column(align=True)
        col1.template_list(camlist,'cameras',camlist,'cameras_i')
        col2.operator('camlist.add_selected',icon='ZOOMIN',text='')
        col2.operator('camlist.remove')
        self.layout.prop(camlist,'cameras')

def register():
    bpy.utils.register_module(__name__)
    bpy.types.Scene.camlist = bpy.props.PointerProperty(type=camlist_property)

def unregister():
    bpy.utils.unregister_module(__name__)

if __name__ == '__main__':
    register()

runs from the text editor or could be placed in user-scripts-startup-folder.

Maybe a bit more clarification of how you want your workflow to go and we can get the text output part done – mac / linux / pc ? save to blender folder or desktop? how is text file used eventually?

This is amazing!
thank you so much dustractor!!

This is exactly what I was trying to do.

I’m using Windows. for saving the text file, I want a file browser to pop up, so that i can select the directory to save into.

There are hundreds of cameras (pictures) to choose from in each scene I have. The list will be used as a guide for designers to create panoramics (this is why I dont want the list to be sorted in any way). Without this they would have to sift through hundreds of pictures that arent always in order because of the way they were photographed (naming convention).
I will also be integrating this into another script I have for image projection, which will speed up that process.

I’m sure the save button will be simple enough to intergrate into your code.
Thanks again!