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$
3
$\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()
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.