How to reimport animation sequence with python

Hi,

I’m using python to reimport SkeletalMesh in Unreal automatically.
I have a SkeletalMesh with 4 animations sequence and i would like to reimport the SkeletalMesh and the animations related, with an FBX.
I reimport the Skeletal using this function:

def import_skeletal(skel, fbx_path):
    import_task = unreal.AssetImportTask()
    import_task.destination_name = skel.get_name()
    import_task.destination_path = skel.get_path_name().rpartition("/")[0] 
    import_task.filename = fbx_path   
    import_task.replace_existing = True   
    import_task.automated = True   
    import_task.factory = unreal.FbxFactory()   
    import_task.options = unreal.FbxImportUI() 
    import_task.options.import_animations = True
    import_task.options.mesh_type_to_import = unreal.FBXImportType.FBXIT_SKELETAL_MESH
    unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([import_task])

and seems import SkeletalMesh without any problem, but doesn’t reimport animations sequence from the fbx.

So when i saw the problem i tried from the editor clicking on Reimport Animation

it asks me for the fbx and it works!

but i’m having a lot of trouble implementing this behavior from python!
I saw that exists the ReimportFbxAnimSequenceFactory and i tried to use it like this:

def reimport_animation(anim_sequence, fbx_path):   
     import_task = unreal.AssetImportTask()   
     import_task.destination_name = anim_sequence.get_name()   
     import_task.destination_path = anim_sequence.get_path_name().rpartition("/")[0]   
     import_task.filename = fbx_path   
     import_task.replace_existing = True   
     import_task.automated = True   
     import_task.factory = unreal.ReimportFbxAnimSequenceFactory() 
     unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([import_task])

but it gives me this error here:

LogAssetTools: Warning: Failed to import ‘path-to-fbx’ Unknown extension ‘fbx’.

so, what is the correct way to replicate the behavior of Reimport Animation with python, or i can reimport SkeletalMesh and animations sequence with one AssetImportTask??

Thanks for the patience!

Did you find any solution to this ? I’m in the same situation. Thanks.

The ‘automated’ property set to True is causing the (false) error.
If you set it to False the import is happening as expected (but there the output log popping at the end).

Similar content, with the exception of the factory, was successful.

def reimport_static_mesh(asset: unreal.StaticMesh):
    import_task = unreal.AssetImportTask()
    import_task.automated = True
    import_task.filename = import_data.get_first_filename()
    import_task.destination_name = asset.get_name()
    import_task.destination_path = asset.get_path_name().rpartition("/")[0]
    # import_task.factory = unreal.ReimportFbxStaticMeshFactory()
    import_task.replace_existing = True
    asset_tools: unreal.AssetTools = unreal.AssetToolsHelpers.get_asset_tools()

    asset_tools.import_asset_tasks([import_task])

For more detail:

import unreal

def reimport_asset(asset_path):

#Return Object(child of _ObjectBase) Class
asset = unreal.EditorAssetLibrary.load_asset(asset_path) 

import_data = asset.get_editor_property("asset_import_data")
#Get fbx path, Ex: 'e:\dev\Player\Animation\Export\PE\A_Pl_Base_005.fbx'
fbx_file_path = import_data.get_first_filename()

import_task = unreal.AssetImportTask()
#Important! Need to assgin fbx path to filename. 
import_task.filename = fbx_file_path 

#get_name() is a class method in _ObjectBase Class
import_task.destination_name = asset.get_name() 
import_task.destination_path = asset.get_path_name().rpartition("/")[0]
#Ignore pop-up window
import_task.replace_existing = True 

asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
asset_tools.import_asset_tasks([import_task])

asset_path = ‘/Game/Player/Base/Animation/A_Pl_Base_PE_005’

reimport_asset(asset_path)

Is there really no way of reimporting automatically? It’s very annoying to have to have the dialog appear