3
$\begingroup$

I tried to extend my own Operator but it doesn't work.

What am I doing wrong?

If I add this operator I get "Test"

class OperatorX(bpy.types.Operator):
bl_idname = "test.x"
bl_label = "Test X"

strprop = bpy.props.StringProperty(default = "Test")

def execute(self, context):
    print(self.strprop)
    return {'FINISHED'}

Then I add the next operator extends the first.

class OperatorY(OperatorX):
bl_idname = "test.y"
bl_label = "Test Y"

def execute(self, context):
    print(self.strprop)
    return {'FINISHED'}

If I call OperatorX I get:

bpy_class_call: unable to get python class for rna struct 'TEST_OT_x'

And if I call OperatorY I get:

(<built-in function StringProperty>, {'attr': 'strprop', 'default': 'Test'})

I need a few operators with the same properties but different execution. How to solve it?

Florian

$\endgroup$
1

1 Answer 1

3
$\begingroup$

@batFINGER: Thank you! It works.

I've done it like this now:

import bpy

class Base:
    strprop = bpy.props.StringProperty(default = "Test")

class MyOperator(bpy.types.Operator, Base):
    bl_idname = "object.my_operator"
    bl_label = "My Operator"

    def execute(self, context):
        print(self.strprop)
        return {'FINISHED'}

bpy.utils.register_class(MyOperator)
$\endgroup$
1
  • 1
    $\begingroup$ That's the one. Small heads up, need to follow the naming convention eg OBJECT_OT_my_operator in 2.8 $\endgroup$
    – batFINGER
    Commented Jul 4, 2018 at 6:45

You must log in to answer this question.

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