Export Selected with Python or Blueprint?

I have a workflow where I click on a StaticMeshActor in the Outliner, and then go to File > Export Selected and export to an OBJ file.

How can I access this task from python or blueprints?

From python I’ve tried something like:

actors = list(editor.get_all_level_actors())

sm_objects = []
for actor in actors:
    if isinstance(actor, unreal.StaticMeshActor):
        sm_objects.append(actor)

exporter = unreal.StaticMeshExporterOBJ()

sm_object = sm_objects[0]

task = unreal.AssetExportTask()
task.automated = True
task.filename = 'blah.obj'
task.object = sm_object.static_mesh_component.static_mesh
task.options = exporter
task.prompt = True
task.replace_identical = True

exporter.run_asset_export_task(task)

but this does not appear to be calling the same task under the hood.

1 Like

I figured out a solution, here it is for anyone interested

def export_all():
    """
    Export all static mesh actors to an obj file.
    """
    editor = unreal.EditorActorSubsystem()
    world = unreal.EditorLevelLibrary.get_editor_world()

    def export_actor(filename):
        exporter = unreal.LevelExporterOBJ()

        task = unreal.AssetExportTask()
        task.selected = True
        task.filename = filename
        task.object = world
        task.exporter = exporter
        task.replace_identical = True

        exporter.run_asset_export_task(task)

    # Find all the static mesh actors
    actors: List[unreal.Actor] = list(editor.get_all_level_actors())

    sm_actors = []
    for actor in actors:
        if isinstance(actor, unreal.StaticMeshActor):
            sm_actors.append(actor)

    print(f'found {len(sm_actors)} static mesh actors')

    # Export all the selected actors
    output_dir = 'E:/'

    for actor in sm_actors:
        folder_path = str(actor.get_folder_path())
        name = str(actor.get_name())
        full_name = f'{folder_path}/{name}'.replace('/', '-')
        obj_file = f'{output_dir}/{full_name}.obj'
        print(f'{obj_file=}')

        editor.select_nothing()
        editor.set_selected_level_actors([actor])

        export_actor(obj_file)