Warning with Inheriting from a Class that Inherits bpy.types.Panel

Hello!

I am creating an add-on that extends the functionality of the default .fbx file importer. I want to use a lot of the user interface for importing a file, so I am inheriting a lot of the classes from the .fbx importer add-on. You can see an example of that here:

class Test_FBX_PT_import_include(bpy.types.FBX_PT_import_include):
    bl_space_type = 'FILE_BROWSER'
    bl_region_type = 'TOOL_PROPS'
    bl_label = "Include"
    bl_parent_id = "FILE_PT_operator"

    @classmethod
    def poll(cls, context):
        sfile = context.space_data
        operator = sfile.active_operator

        return operator.bl_idname == "IMPORT_SCENE_OT_test_fbx"

This works, but I am getting the following warning every time the panel is drawn:

WARN (bpy.rna): C:\Users\blender\git\blender-v360\blender.git\source\blender\python\intern\bpy_rna.c:8422 bpy_class_call: unable to get Python class for RNA struct 'FBX_PT_import_include'

I am not able to find much information on this warning. What does it mean and how do I fix it?

Thank you for any help. I very much appreciate it.

Does removing the first underscore between Test and FBX, i.e., TestFBX_PT_import_include solve the issue?

No, removing the underscore did not solve the issue. I still get the same warning.
I still appreciate the attempt to help. Thank you.

Here’s a few threads that might help:

It seems like it is possible, though it doesn’t necessarily work exactly how you expect.
Instead of creating a custom panel that inherits from a predefined panel they want you to create an abstract class with all your custom info, then create a standard panel that inherits from your abstract class and bpy.types.Panel.
From one of the links (though others suggest putting the mixin class before the Blender class):

class CommonProps:
    s = StringProperty(name="s",default="ABC")

class Base(bpy.types.PropertyGroup, CommonProps):
    pass

class Child(bpy.types.PropertyGroup, CommonProps):
    pass

I get what you are saying here with the mix-in classes. Looking at your example, it really wouldn’t work for my scenario. The base class I am trying to use is a part of a separate add-on. I don’t have the ability to change the class. Is that the only option or is there another way to make this work? Thanks.

Just to iterate, you can’t subclass most blender API python classes, but you can use multiple inheritance to add custom behaviour to your classes. eg if you want to define a specific poll method for all your panels.

class MyPanelBase:
    @classmethod
    def poll(cls, context):
        return context.object and context.object.type == "MESH"

class MyPanelLocation(bpy.types.Panel, MyPanelBase):
    def draw(self, context):
        self.layout.prop(context.object, "location")

class MyPanelScale(bpy.types.Panel, MyPanelBase):
    def draw(self, context):
        self.layout.prop(context.object, "scale")

This example won’t work out of the box but it’s here to illustrate with a practical example.

Maybe you should look into monkey-patching the original class ?

1 Like
@classmethod
def poll(cls, context):
    sfile = context.space_data
    operator = sfile.active_operator

    return operator.bl_idname == "IMPORT_SCENE_OT_test_fbx"

bpy.types.FBX_PT_import_include.poll = poll

This worked. Thank you so much!

2 Likes

I would just suggest a bit of caution, if you disable your addon the panel might not work correctly anymore, or throw errors in the console, you can store the previous poll method somewhere and re-assign on unregister.

1 Like

Oh, great advice. I’ll do that.
Thank you for this!