Hi,
I am looking for a Python script that reimports the selected static mesh with the new file
I looked at the documentation for the Python API and could not find the needed functionality.
I want the script to do the same actions as if you pressed “Reimport With New File”.
This worked for me. If you want to reimport from the different path, then change “filename” in the asset_import_data
import unreal
def reimport_static_mesh(asset_path):
"""
Reimports a static mesh asset in Unreal Engine.
Args:
asset_path (str): The path to the static mesh asset in the content browser
(e.g. '/Game/Meshes/MyMesh')
Returns:
bool: True if the reimport was successful, False otherwise
"""
# Load the static mesh asset
static_mesh = unreal.EditorAssetLibrary.load_asset(asset_path)
if not static_mesh:
print(f"Error: Could not find static mesh at {asset_path}")
return False
# Verify that the asset is a static mesh
if not static_mesh.is_a(unreal.StaticMesh):
print(f"Error: Asset at {asset_path} is not a static mesh")
return False
# Get the asset import data
asset_import_data = static_mesh.get_editor_property('asset_import_data')
if not asset_import_data:
print(f"Error: No import data found for {asset_path}")
return False
# Create a reimport context
reimport_context = unreal.AssetImportTask()
reimport_context.set_editor_property('filename', asset_import_data.get_first_filename())
reimport_context.set_editor_property('destination_path', unreal.Paths.get_path(asset_path))
reimport_context.set_editor_property('destination_name', unreal.Paths.get_base_filename(asset_path))
reimport_context.set_editor_property('replace_existing', True)
reimport_context.set_editor_property('automated', True)
# Perform the reimport
unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([reimport_context])
print(f"Successfully reimported {asset_path}")
return True
# Example usage
# reimport_static_mesh('/Game/Meshes/MyStaticMesh')
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.