Dynamic creation of properties for export script This time I have a question about Properties in Blender. I want the operator window of my add-on to have one BoolProperty per action defined in bpy.data.actions and I want them to have the names from bpy.data.actions.keys(). I googled a bit and tried some stuff, but it wont work, theres allways something wrong, so is this even possible and can someone give me some hints on how to do it? 

class ExportTSA(bpy.types.Operator, ExportHelper):

    actionprop0 = BoolProperty(name=bpy.data.actions.keys()[0],description="Exporet this action",default=True)
    actionprop1 = BoolProperty(name=bpy.data.actions.keys()[1],description="Exporet this action",default=True)
    actionprop2 = BoolProperty(name=bpy.data.actions.keys()[2],description="Exporet this action",default=True)
    actionprop3 = BoolProperty(name=bpy.data.actions.keys()[3],description="Exporet this action",default=True)

    def draw(self, context):
        layout = self.layout

        row = layout.row()
        row.prop(self,"actionprop0")
        row = layout.row()
        row.prop(self,"actionprop1")
        row = layout.row()
        row.prop(self,"actionprop2")
        row = layout.row()
        row.prop(self,"actionprop3")


Heres a simplified version of my class, to demonstrate the idea. Instead of making hardcoded props like actionprop0, actionprop1... I want it to be dynamic in a way that it creates an automatic list, assigns the correct names, registers each one and draws them. I also found that you get into trouble when using bpy.data.actions where I used it, after I googled it it turns out that blender seems to be not fully initialized at that point so that causes errors, which might lead to additional problems.
In addition to what Adhi suggested, you can use CollectionProperty in your operator to store key value pairs (where keys are name of the action and values are boolean values). For this to work you must...


create a subclass of PropertyGroup that will hold single key-value pair.
populate this collection from Operator.invoke method (you might already have it)


So the code goes like this:

import bpy
from bpy_extras.io_utils import ExportHelper
from bpy.props import *

class ActionSelProperty(bpy.types.PropertyGroup):
    name = StringProperty(name="Action Name")
    export = BoolProperty(name="Export", description="Exporet this action", default=True)

class ExportTSA(bpy.types.Operator, ExportHelper):
    bl_idname = "test.export_tsa_op"
    bl_label = "Export TSA"

    actionprop = CollectionProperty(name="Actions", type=ActionSelProperty, description="Select actions to exporet")
    filename_ext = "*.*" # Only needed if subclassing `ExportHelper`

    def invoke(self, context, event):
        for aname in bpy.data.actions.keys():
            self.actionprop.add().name = aname
        wm = context.window_manager
        wm.fileselect_add(self)
        return {'RUNNING_MODAL'}

    def draw(self, context):
        layout = self.layout

        for aindx in range(len(self.actionprop)):
            row = layout.row()
            row.prop(self.actionprop[aindx], "export", text=self.actionprop[aindx].name)

    def execute(self, context):
        for aprop in self.actionprop:
            print("%s:\t%s" % (aprop.name, aprop.export))
        return {'FINISHED'}

def register():
    bpy.utils.register_module(__name__)

if __name__ == "__main__":
    register()


In this case,  name is a key and export is a boolean value.

PS: Invoke by searching Export TSA. Screenshots:

 

This may not be perfect, but you can investigate more! :)

HTH