0
$\begingroup$

I'm aiming to bulk import about 20 - 50 FBX animations, but I'd like to rename them based on the filename they come from.

I currently have the following...

def addCollection(colName):
    collectionFound = False

    for myCol in bpy.data.collections:
        print(myCol.name)
        if myCol.name == my_coll:
            collectionFound = True
            return("Collection found in scene")
            
    if collectionFound == False:
        myCol = bpy.data.collections.new(my_coll)
        bpy.context.scene.collection.children.link(myCol) #Creates a new collection
        return("created")

Also, would I need to push_down(), if I plan on laying actions?

$\endgroup$

1 Answer 1

0
$\begingroup$

It always seems to be the way, you post a question that has stopped you for an hour or so. and then work it out.

import bpy
import os

def listFiles(dir, ext):
    fileList = []
    for file in os.listdir(dir):
        print(file)
        if file[-len(ext):] == ext:
            fileList.append(file)
    return fileList

currentDir = bpy.path.abspath('//') 
AniDir = currentDir+'Animations'
ext = '.fbx'

# Create a Templ Coillection to work within
collection = bpy.data.collections.new('TempCollection')
bpy.context.scene.collection.children.link(collection)
layer_collection = bpy.context.view_layer.layer_collection.children[collection.name]
bpy.context.view_layer.active_layer_collection = layer_collection

# Import all the Animations and rename them to the Filename
for Animations in listFiles(AniDir, ext):
    AniFile = AniDir + '//' + Animations
    bpy.ops.import_scene.fbx(filepath=AniFile,directory=AniDir, filter_glob='*.fbx',use_anim=True)
    obj = bpy.context.object
    obj.animation_data.action.name = bpy.path.display_name_from_filepath(AniFile)
$\endgroup$

You must log in to answer this question.

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