Download

Using api python Exporter

Hello,

Currently I am trying to export an entire level through the editor. Currently I am going about it this way:

reg = unreal.AssetRegistryHelpers
regy = reg.get_asset_registry()
objs = regy.get_assets_by_path(’/Game/path’,recursive=True) #need to use .get_asset to add asset to task
exportTask = unreal.AssetExportTask()
exportTask.set_editor_property(‘object’,‘Actual object.get_asset()’)
exportTask.set_editor_property(‘filename’,‘Example’)
exporter = unreal.Exporter
exporter.run_asset_export_task(exportTask)

However it always crashes so I assume I’m doing it wrong. Is there a better way to go about exporting a level?

Hi, I wasn’t sure if by level you meant export every single object in your game, or just the actual “World” object.
I think this might help though:



def export_level(level_name="MyLevel"):
    asset_registry = unreal.AssetRegistryHelpers.get_asset_registry()
    levels = asset_registry.get_assets_by_class("World")

    level_to_export = None
    for level in levels:
        if level.get_editor_property("asset_name") == level_name:
            level_to_export = level.get_asset()

    if not level_to_export:
        return

    export_task = unreal.AssetExportTask()
    export_task.set_editor_property("object", level_to_export)
    export_task.set_editor_property("filename", "C:\	est\\{}_exportData".format(level_name))
    export_task.set_editor_property("automated", True)
    export_task.set_editor_property("exporter", unreal.LevelExporterLOD())

    unreal.Exporter.run_asset_export_task(export_task)


This was incredibly helpful! The small error I am having with it is that it is prompting for FBX settings when I run the function, is there anyway to circumvent this?

If you changed LevelExporterLOD to LevelExporterFBX, I think the way to bypass the prompt would be to add:



export_option = unreal.FbxExportOption()

export_task.set_editor_property("options", export_option)
export_task.set_editor_property("prompt", False)


Just add those 3 lines before you export the task and you shouldn’t get a window popup.

Hello!How can i export selected meshes one by one.It merges all the actors and exports as a single mesh.I appreciate any help! Thanks!

Would try something like:

selected_actors = unreal.EditorLevelLibrary.get_selected_level_actors()

for actor in selected_actors:
    unreal.EditorLevelLibrary().select_nothing()
    unreal.EditorLevelLibrary().set_selected_level_actors([actor])

    # Export stuff

Basically just creating a new export task for each selected object.

Thank you.It works :slight_smile: