2
$\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$
2
$\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
    $\begingroup$ That's the one. Small heads up, need to follow the naming convention eg OBJECT_OT_my_operator in 2.8 $\endgroup$ – batFINGER Jul 4 '18 at 6:45

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.