How can I get the .fbx source file path from a static mesh asset using python editor scripting?

I’ve gotten as far as having a FbxStaticMeshImportData object and a AssetImportInfo object. But I’m struggling to figure out how the get source file path from there.
Any help greatly appreciated.

import unreal
asset_path = "/Game/"
all_assets = unreal.EditorAssetLibrary.list_assets(asset_path)
all_assets_loaded = [unreal.EditorAssetLibrary.load_asset(a) for a in all_assets]
static_mesh_assets = unreal.EditorFilterLibrary.by_class(all_assets_loaded, unreal.StaticMesh)
import_data = static_mesh_assets[0].get_editor_property("asset_import_data")
print("import_data", type(import_data), import_data)
# import_data object type is FbxStaticMeshImportData
source_data = import_data.get_editor_property("source_data")
# source_data object type is AssetImportInfo
print("source_data", type(source_data), source_data)

def get_all_assets(context=“/Game/”):
asset_objects = list()
for asset in unreal.EditorAssetLibrary.list_assets(context):
asset_objects.append(unreal.load_asset(asset))
return asset_objects

def get_all_fbx_files(context="/Game/"):
    loaded_assets = get_all_assets(context)
    animation_sequences = unreal.EditorFilterLibrary.by_class(loaded_assets, unreal.AnimSequence)

    all_source_files = list()
    for anim_sequence in animation_sequences:
        import_data = anim_sequence.get_editor_property("asset_import_data")
        source_files = import_data.extract_filenames()
        all_source_files.extend([f for f in source_files if f.endswith(".fbx")])

    return all_source_files
1 Like
    folder_path  = 'D:'
    now_selects = unreal.EditorUtilityLibrary.get_selected_assets()

    for now_asset in now_selects:
        #Get file name
        asset_name = now_asset.get_name()
        print('asset_name = {0}'.format(asset_name))

        #Get asset's import data
        import_data = now_asset.get_editor_property("asset_import_data")

        #Get asset's original source file path
        source_files = import_data.extract_filenames()
        print('source_files = {0}'.format(source_files))

        #Set source file path
        new_source_file = folder_path + '/' + asset_name + '.png' #Combine as you wish
        source_files = import_data.scripted_add_filename(new_source_file,0,'')