4
$\begingroup$

I'd like to iterate over the properties (names and values) of a dialog operator in its execute method.

My current way of doing this involves a metaclass and multiple inheritance...

Is there any simpler way?

$\endgroup$

1 Answer 1

4
$\begingroup$

To iterate over all RNA properties you can access:

self.rna_type.properties.keys(),

In most cases you'll want to skip rna_type, which is added automatically.


Example operator which prints its properties in order.

import bpy
from bpy.props import StringProperty

class SimpleOperator(bpy.types.Operator):
    bl_idname = "object.simple_operator"
    bl_label = "Simple Operator"

    foo = StringProperty()
    bar = StringProperty()
    baz = StringProperty()
    spam = StringProperty()

    def execute(self, context):
        for k in self.rna_type.properties.keys():
            if k == "rna_type":
                continue
            print(k)
        return {'FINISHED'}


def register():
    bpy.utils.register_class(SimpleOperator)


def unregister():
    bpy.utils.unregister_class(SimpleOperator)

if __name__ == "__main__":
    register()

    # test call
    bpy.ops.object.simple_operator()
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .