0
$\begingroup$

I'm having difficulty getting this script to export anything and I'm not sure what I'm missing. It is meant to export a specified collection.

def fbxporter(collName):
    C = bpy.context
    # Deselect all objects
    for obj in bpy.context.selected_objects:
        obj.select_set(False)

    for coll in C.collection.objects:
        if coll.name==collName:
            for obj in bpy.context.selected_objects:
                obj.select_set(True)
                # Select all objects in collection
                # export selected
                # Save as strin(filename)+'_'+str(collection.name)
                bpy.ops.export_scene.fbx(
                    filepath=bpy.path.abspath("//{}.fbx".format(C.collection.name)),
                    # Object types: just mesh
                    object_types = 'MESH',
                    # Units = fbx all
                    apply_scale_options = 'FBX_SCALE_UNITS',
                    # Triangulatefaces  = true
                    use_triangles = False,
                    # Apply modifiers
                    use_mesh_modifiers = True,
                    # Tangents = true
                    use_tspace = True,
                    path_mode = 'AUTO',
                    embed_textures = True,
                    use_selection = True
                )

fbxporter('low')
$\endgroup$

1 Answer 1

0
$\begingroup$

API - https://docs.blender.org/api/current/bpy.ops.export_scene.html#bpy.ops.export_scene.fbx

import bpy

# Save the blend file first

def fbxporter(coll_name):
    ''' Export object from a collection.

    coll_name (str) - Name of the collection to export.
    '''

    for object in bpy.data.collections[coll_name].objects:
        bpy.ops.export_scene.fbx(
            filepath = bpy.path.abspath(f'//{object.name}.fbx'),
            object_types = {'MESH'},
            apply_scale_options = 'FBX_SCALE_UNITS',
            use_triangles = False,
            use_mesh_modifiers = True,
            use_tspace = True,
            path_mode = 'AUTO',
            embed_textures = True,
            use_selection = True)

fbxporter('Collection')
$\endgroup$

You must log in to answer this question.

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