Batch Export for different formats using bpy.ops.export_scene

The blender 2.81 batch_export.py template is a nifty set of code but it looks like the only supported formats are FBX, x3d, obj, and gltf. The template uses byp.ops.export_scene : https://docs.blender.org/api/current/bpy.ops.export_scene.html

How would i access other exporters such as .chan? since bpy.ops.export_scene.chan does not work

I’m trying to export a batch of .chan (Nuke) files because i want animation data in ascii format in a different file for each object in a scene.

Looks like there are similar questions for other formats that are less popular as well such as DXF, 3DS, ASE, so i think a generic answer where any import/export addon can be figured out would be most useful.

Thanks!

If anyone is running into similar things check out the __ init __.py file in the addon folder and look for something similar to this for your file exporter:

class ExportChan(Operator, ExportHelper):
    """Export the animation to .chan file, readable by nuke and houdini """ \
    """(the exporter uses frames from the frames range)"""
    bl_idname = "export.export_chan"
    bl_label = "Export chan file"

    filename_ext = ".chan"
    filter_glob: StringProperty(default="*.chan", options={'HIDDEN'})
    y_up: BoolProperty(
            name="Make Y up",
            description="Switch the Y and Z axis",
            default=True)
    rotation_order: rotation_order

    @classmethod
    def poll(cls, context):
        return context.active_object is not None

    def execute(self, context):
        from . import export_nuke_chan
        return export_nuke_chan.save_chan(context,
                                          self.filepath,
                                          self.y_up,
                                          self.rotation_order)

So for Nuke (.chan) files it is bpy.ops.export.export_chan(filepath=fn + “.chan”)
you can also set the y_up and rotation_order.

The final script for batch exporting Nuke (.chan) fils is:

# exports each selected object into its own file

import bpy
import os

# export to blend file location
basedir = os.path.dirname(bpy.data.filepath)

if not basedir:
    raise Exception("Blend file is not saved")

view_layer = bpy.context.view_layer

obj_active = view_layer.objects.active
selection = bpy.context.selected_objects

bpy.ops.object.select_all(action='DESELECT')

for obj in selection:

    obj.select_set(True)

    # some exporters only use the active object
    view_layer.objects.active = obj

    name = bpy.path.clean_name(obj.name)
    fn = os.path.join(basedir, name)

    # Can be used for multiple formats
    # bpy.ops.export_scene.x3d(filepath=fn + ".x3d", use_selection=True)
    # bpy.ops.export_scene.fbx(filepath=fn + ".fbx", use_selection=True)
 
    bpy.ops.export.export_chan(filepath=fn + ".chan")

    obj.select_set(False)

    print("written:", fn)


view_layer.objects.active = obj_active

for obj in selection:
    obj.select_set(True)