How to get a reference to the ExportGLTF2 operator?

I’m hacking the GLTF exporter plugin and trying to add an eyedropper operator that can be used to pick a bone from a rig and then add it to a CollectionProperty that I’ve added to the main ExportGLTF2_Base operator. The trouble is, I can’t figure out how to get a reference to ExportGLTF2 from my eyedropper operator. I thought it would be registered as bpy.types.ExportGLTF2, but I can’t find anything there with that or a similar name.

This is the operator that gets called from my eyedropper button:

class OBJECT_OT_bone_list_actions(bpy.types.Operator):
    bl_idname = "object.bone_list_actions"
    bl_label = "Bone List Actions"
    bl_options = {"REGISTER", "UNDO"}

    action: bpy.props.EnumProperty(
        items=(
            ("ADD", "Add", "Add a new bone slot"),
            ("ADD_SELECTED", "Add Selected", "Add currently selected bones"),
            ("REMOVE", "Remove", "Remove active bone slot"),
        )
    )

    def execute(self, context):
        # Set obj to the ExportGLTF2 operator
        obj = ???

        idx = obj.export_bone_include_list_index

        if self.action == "ADD":
            item = obj.export_bone_include_list.add()
            obj.export_bone_include_list_index = len(obj.export_bone_include_list) - 1

        elif self.action == "ADD_SELECTED":
            # Works in both Pose Mode and Edit Mode
            selected = context.selected_pose_bones or context.selected_bones
            if selected:
                existing_names = {item.name for item in obj.export_bone_include_list}
                for bone in selected:
                    if bone.name not in existing_names:
                        item = obj.export_bone_include_list.add()
                        item.name = bone.name
                obj.export_bone_include_list_index = len(obj.export_bone_include_list) - 1

        elif self.action == "REMOVE":
            if len(obj.export_bone_include_list) > 0:
                obj.export_bone_include_list.remove(idx)
                obj.export_bone_include_list_index = max(0, idx - 1)

        return {"FINISHED"}

export_bone_include_list and export_bone_include_list_index are new properties I’ve added to ExportGLTF2_Base.

The ExportGLTF2 exyends ExportGLTF2_Base, and they’re registered like this:

classes = (
    # My Additions
    BoneItem,
    OBJECT_OT_bone_list_actions,
    OBJECT_UL_bone_list,
    # From the original source
    ExportGLTF2,
    ImportGLTF2,
    IO_FH_gltf2,
    GLTF2_filter_action,
    GLTF_AddonPreferences
)


def register():
    from .blender.com import gltf2_blender_ui as blender_ui

    for c in classes:
        bpy.utils.register_class(c)

What would be the right way to get the ExportGLTF2 operator?

Source project:

What exactly are you trying to do? I mean functionality wise - what do you need the add-on to do?

Allow the user to select bones to be included in the export. That way you can check the ‘deformation bones only’ box so that only deformation bones are exported, but also include a few key non-deformation bones that you’re using to track critical points. Otherwise this plugin will export a lot of unnecessary bones for a rig.

Right now you have to choose between only deformation bones, or everything. This lets you limit things to the deformation bones, plus a few key bones.

I think any eyedropper “selects” any blender internal structure and you might be able to add some custom data to it so that “some exporter” uses this info to do some “extra” work on the geometry.. in fact that’s what you wanna add to the exporter. Native blender does not know about the export format nor how to manipulate that data. Any “editing features” has to be done by the addon/extension.

So you have to understand how the exporter generates the new data (very) deeply.

I’ve written plugins that can use an eyedropper to select objects before and store them in a CollectionProperty list. What I can’t figure out is where I can find the ExportGLTF2 operator so that I can modify the property I’ve added to it. So I just need to figure out it’s name so I can get it and access it’s properties.

After a very quick look i have the impression that for this the base class ConvertGLTF2_Base

is directly afterwards “extendes” by the class ExportGLTF2_Base to “collect” all the export_.. method to do so (especially in the execute method )..

..but that may be a very quick look :wink:

Yes, that is the base class ExportGLTF2 extends. It is instantiated as an operator. I was thinking it would be stored as a child of bpy.types, but it’s not there. I need to know how I can get a reference to it so that I can access it’s properties.

Ohhh.. that’s gonna by some deep dive :goggles: :wink:

OK, I am not sure I understand what is going on, but GLTF exporter already seems full of various features. Wouldn’t it be easier to export an active collection with everything you need? You can have multiple collections with various combinations of objects in them and same objects can be in multiple collections if needed that way you don’t need to select objects by hand every time you want to export. Doesn’t that work for this?

You can’t have a collection of individual bones from a rig. And it would be a real pain to have to reselect every bone you want to export each time you export your model just to make sure that you include a few special guide bones in your export.

This is meant for rigged character models being exported to a game engine. With the current design, you need to either choose deformation bones, or if you want non-deformation bones too, that will include every single control bone as well, which can increase the number of bones exported by something like 2.5x with mostly useless bones just so you can get the two or three extra that you need.

I think the question is more like:

If you need that much of bones in the original software, then why do you only need to export a few of them ?
It seems that the others are not needed, so why add them to the rig in the first place ?

..so this might be a XY-problem ?

Maybe @MartinZ and i “simply” does not see the “need” or use case for this but at least i’m eager to learn something new. :wink:

Most rigs have control bones, expecially if you use a system like rigify. Control bones provide ways to see and manipulate handles, and can also act as intermediate bones to restrict motion or provide stretching or other effects. They’re great for animation, but you don’t want them exported to a game rig. However, sometimes there are a few non deform bones you do want to export to indicate special locations on your rig. Since non-deform bones can often be around 2/3 of the bones in your rig, you usually don’t export them. But sometimes you do want to make exceptions for specific bones.

But in any case, my question isn’t even about bones. I’m trying to figure out how to find the operator object so that I can access the properties I’ve added to it. The class is registered as bpy.ops.import_scene.gltf or bpy.types.EXPORT_SCENE_OT_gltf, but I don’t know how to access the properties I’ve added to it from a custom operator.

Hmm… i think you need to process any beforehand added custom properties while the GLTF exporter “gathers” the info from blender here in gather_joint_vnode(..) function:

    Generate a glTF2 node from a blender bone, as joints in glTF2 are simply nodes.

Just to clarify. I don’t know much about rigs. That was an honest question to the OP. I know about bpy though. So like I tried to answer in another thread - I think you are trying to do this in a way it’s not meant to be done. Properties should be created in the right places. Operator properties are meant for that operator to use and you don’t create properties inside one operator that are then accesses by others. If you need multiple operators to use some properties, they should belong to something else so that those operators then can access them. That’s the general idea.

That’s an XY problem. You don’t do this. I think that’s the answer. Create the properties somewhere else - on the scene, objects, window manager, add-on preferences or something like that if you need to use them with multiple operators.