Export mesh as GLTF with Python

What about:

import unreal

selected_assets = unreal.EditorUtilityLibrary.get_selected_assets()
for asset in selected_assets:
    # set up the gltf export options
    task = unreal.AssetExportTask()
    task.object = asset
    task.filename = "C:/Temp/GLTFExport/"+asset.get_name() + ".gltf"
    task.automated = True           # don't display the export options dialog
    task.replace_identical = True   # always overwrite the output
    task.exporter = unreal.GLTFStaticMeshExporter()
    task.options = unreal.GLTFExportOptions()
    result = unreal.Exporter.run_asset_export_task(task)

This plugin is on the marketplace, thus it is not processed to be added to the official python API.
What you can do is

  1. Turn GLTF Exporter plugin and python plugin on in your project
  2. in project settings, python, turn developer mode on
    image
  3. restart project, look into “Intermediate\PythonStub\unreal.py” you will have the python API including the one for the activated plugins.

Bonus, you can use this stub in your IDE to get some autocompletion.

Bests,
Flavien.

1 Like