# Trouble exporting in glTF using python

**URL:** <https://forums.unrealengine.com/t/trouble-exporting-in-gltf-using-python/564897>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [May 24, 2022, 5:40am UTC](https://forums.unrealengine.com/t/trouble-exporting-in-gltf-using-python/564897 "2022-05-24T05:40:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Drkstr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Drkstr](https://forums.unrealengine.com/u/Drkstr)\
**Post date:** [May 24, 2022, 5:40am UTC](https://forums.unrealengine.com/t/trouble-exporting-in-gltf-using-python/564897/1 "2022-05-24T05:40:55Z")

</div>

I am trying to import an fbx file and export it as a glTF file using python scripts.

I am trying to use [this](https://www.unrealengine.com/marketplace/en-US/product/gltf-exporter) plugin for the glTF export.

Here is how I import the file into unreal

```auto
def import_asset_noncad():
    """ Import Non-Cad Asset """
    # Bicycle.obj
    # Bulk_Filling_Tank.fbx
    destination_path = '/Game/NonCad/'
    filenames = [input_filename]
    editorAssetLibrary = unreal.EditorAssetLibrary()

    # delete asset
    assets_list = editorAssetLibrary.list_assets(destination_path)
    for asset in assets_list:
        editorAssetLibrary.delete_asset(asset)
    # import asset task
    data = unreal.AutomatedAssetImportData()
    data.set_editor_property('destination_path', destination_path)
    data.set_editor_property('filenames', filenames)
    destination_name = os.path.basename(os.path.splitext(filenames[0])[0])
    data.set_editor_property('group_name', 'fbx')
    data.set_editor_property('replace_existing', True)
    # scene import options
    scene = unreal.FbxSceneImportOptions()
    scene.set_editor_property('create_content_folder_hierarchy', True)
    scene.set_editor_property('import_as_dynamic', True)
    layer_type = unreal.FBXSceneOptionsCreateHierarchyType.FBXSOCHT_CREATE_LEVEL_ACTORS
    scene.set_editor_property('hierarchy_type', layer_type)
    # scene import options(static mesh) for factory
    static_meshes = unreal.FbxSceneImportOptionsStaticMesh()
    # static_meshes.set_editor_property('auto_generate_collision', False)
    static_meshes.set_editor_property('generate_lightmap_u_vs', False)
    normal_method = unreal.FBXSceneNormalImportMethod.FBX_SCENE_NIM_IMPORT_NORMALS
    static_meshes.set_editor_property('normal_import_method', normal_method)
    # fbx scene import factory
    factory = unreal.FbxSceneImportFactory()
    factory.set_editor_property('scene_import_options', scene)
    factory.set_editor_property('scene_import_options_static_mesh', static_meshes)
    data.set_editor_property('factory', factory)
    # run task
    asset = unreal.AssetToolsHelpers.get_asset_tools().import_assets_automated(data)
    # load asset
    assets_list = editorAssetLibrary.list_assets(destination_path)
    for asset in assets_list:
        editorAssetLibrary.load_asset(asset)

```

Here is how I trying to export to glTF

```auto
def export_gltf_model():
    output_filename = ('{}{}{}.{}').format(output_filelocation, "/", model_name, "gltf")
    level_actors = unreal.EditorLevelLibrary.get_all_level_actors()
    task = unreal.AssetExportTask()
    # obj = level_actors[0].get_world()
    task.exporter = unreal.GLTFStaticMeshExporter()
    task.set_editor_property('options', unreal.GLTFExportOptions())
    task.set_editor_property('object', level_actors[0])
    task.set_editor_property('filename', output_filename)
    # task.set_editor_property('selected', False)
    # task.set_editor_property('prompt', False)
    task.set_editor_property('automated', True)
    task.set_editor_property('replace_identical', True)
    result = unreal.Exporter.run_asset_export_task(task)
    if (result):
        print('DONE! Output {} File Path and name: {}'.format(export_format, output_filename))
    else:
        print("Export failed")

```

When I run the above code, the editor crashes.

Question: How would I export a model as a glTF using python in Unreal.

Here is what I get in the crash report.

```auto
LoginId:baf048eb204944da5d657396450e0a23
EpicAccountId:5b86c5a63b144d6cae3cce7bbdf5c5ac

Assertion failed: Object->IsA( Exporter->SupportedClass ) [File:/Users/build/Build/++UE4/Sync/Engine/Source/Runtime/Engine/Private/UnrealExporter.cpp] [Line: 167]

FGenericPlatformMisc::RaiseException(unsigned int) Address = 0x10ab5b2b7 (filename not found) [in UE4Editor-Core.dylib]
FMacErrorOutputDevice::Serialize(char16_t const*, ELogVerbosity::Type, FName const&) Address = 0x10ad14e53 (filename not found) [in UE4Editor-Core.dylib]
FOutputDevice::LogfImpl(char16_t const*, ...) Address = 0x10ae2e689 (filename not found) [in UE4Editor-Core.dylib]
AssertFailedImplV(char const*, char const*, int, char16_t const*, __va_list_tag*) Address = 0x10ada0b57 (filename not found) [in UE4Editor-Core.dylib]
FDebug::CheckVerifyFailedImpl(char const*, char const*, int, char16_t const*, ...) Address = 0x10ada09e4 (filename not found) [in UE4Editor-Core.dylib]
UExporter::RunAssetExportTask(UAssetExportTask*) Address = 0x1141d1037 (filename not found) [in UE4Editor-Engine.dylib]
UExporter::execRunAssetExportTask(UObject*, FFrame&, void*) Address = 0x114482c7e (filename not found) [in UE4Editor-Engine.dylib]
UFunction::Invoke(UObject*, FFrame&, void*) Address = 0x109848c3c (filename not found) [in UE4Editor-CoreUObject.dylib]
UObject::ProcessEvent(UFunction*, void*) Address = 0x109b157bc (filename not found) [in UE4Editor-CoreUObject.dylib]
PyUtil::InvokeFunctionCall(UObject*, UFunction const*, void*, char16_t const*) Address = 0x285cabdbd (filename not found) [in UE4Editor-PythonScriptPlugin.dylib]
FPyWrapperObject::CallFunction_Impl(UObject*, _object*, _object*, PyGenUtil::FGeneratedWrappedFunction const&, char const*, char16_t const*) Address = 0x285d1f626 (filename not found) [in UE4Editor-PythonScriptPlugin.dylib]
FPyWrapperObject::CallFunction(_typeobject*, _object*, _object*, PyGenUtil::FGeneratedWrappedFunction const&, char const*) Address = 0x285d1f2ee (filename not found) [in UE4Editor-PythonScriptPlugin.dylib]
_PyObject_FastCallKeywords Address = 0x285fee24f (filename not found) [in libpython3.7.dylib]
call_function Address = 0x2860bca20 (filename not found) [in libpython3.7.dylib]
_PyEval_EvalFrameDefault Address = 0x2860b9551 (filename not found) [in libpython3.7.dylib]
function_code_fastcall Address = 0x285fee91d (filename not found) [in libpython3.7.dylib]
call_function Address = 0x2860bca27 (filename not found) [in libpython3.7.dylib]
_PyEval_EvalFrameDefault Address = 0x2860b95fb (filename not found) [in libpython3.7.dylib]
function_code_fastcall Address = 0x285fee91d (filename not found) [in libpython3.7.dylib]
call_function Address = 0x2860bca27 (filename not found) [in libpython3.7.dylib]
_PyEval_EvalFrameDefault Address = 0x2860b95fb (filename not found) [in libpython3.7.dylib]
_PyEval_EvalCodeWithName Address = 0x2860bd5df (filename not found) [in libpython3.7.dylib]
PyEval_EvalCode Address = 0x2860b27d0 (filename not found) [in libpython3.7.dylib]
FPythonScriptPlugin::EvalString(char16_t const*, char16_t const*, int, _object*, _object*) Address = 0x285cc42b1 (filename not found) [in UE4Editor-PythonScriptPlugin.dylib]
FPythonScriptPlugin::RunFile(char16_t const*, char16_t const*, FPythonCommandEx&) Address = 0x285cbc201 (filename not found) [in UE4Editor-PythonScriptPlugin.dylib]
FPythonScriptPlugin::ExecPythonCommandEx(FPythonCommandEx&) Address = 0x285cbb9c0 (filename not found) [in UE4Editor-PythonScriptPlugin.dylib]
FPythonScriptPlugin::ExecPythonCommand(char16_t const*) Address = 0x285cbb7ac (filename not found) [in UE4Editor-PythonScriptPlugin.dylib]
FPythonCommandExecutor::Exec(char16_t const*) Address = 0x285cbb1eb (filename not found) [in UE4Editor-PythonScriptPlugin.dylib]
SConsoleInputBox::OnTextCommitted(FText const&, ETextCommit::Type) Address = 0x261d3b6f5 (filename not found) [in UE4Editor-OutputLog.dylib]
TBaseSPMethodDelegateInstance<false, SConsoleInputBox, (ESPMode)0, void (FText const&, ETextCommit::Type), FDefaultDelegateUserPolicy>::ExecuteIfSafe(FText const&, ETextCommit::Type) const Address = 0x261d6238f (filename not found) [in UE4Editor-OutputLog.dylib]
FSlateEditableTextLayout::HandleCarriageReturn(bool) Address = 0x10d238dfb (filename not found) [in UE4Editor-Slate.dylib]
FSlateEditableTextLayout::HandleKeyDown(FKeyEvent const&) Address = 0x10d237161 (filename not found) [in UE4Editor-Slate.dylib]
SMultiLineEditableText::OnKeyDown(FGeometry const&, FKeyEvent const&) Address = 0x10d24cff7 (filename not found) [in UE4Editor-Slate.dylib]
FSlateApplication::ProcessKeyDownEvent(FKeyEvent const&) Address = 0x10cf0fc2f (filename not found) [in UE4Editor-Slate.dylib]
FSlateApplication::OnKeyDown(int, unsigned int, bool) Address = 0x10cf0e3aa (filename not found) [in UE4Editor-Slate.dylib]
FMacApplication::ProcessKeyDownEvent(FDeferredMacEvent const&, TSharedPtr<FMacWindow, (ESPMode)0>) Address = 0x108eaba46 (filename not found) [in UE4Editor-ApplicationCore.dylib]
FMacApplication::ProcessEvent(FDeferredMacEvent const&) Address = 0x108ea52b4 (filename not found) [in UE4Editor-ApplicationCore.dylib]
FMacApplication::ProcessDeferredEvents(float) Address = 0x108ea4eaf (filename not found) [in UE4Editor-ApplicationCore.dylib]
FSlateApplication::TickPlatform(float) Address = 0x10ceee590 (filename not found) [in UE4Editor-Slate.dylib]
FSlateApplication::Tick(ESlateTickType) Address = 0x10ceedc11 (filename not found) [in UE4Editor-Slate.dylib]
FEngineLoop::Tick() Address = 0x108961254 (filename not found) [in UE4Editor]
GuardedMain(char16_t const*) Address = 0x10896e92e (filename not found) [in UE4Editor]
-[UE4AppDelegate runGameThread:] Address = 0x10898d413 (filename not found) [in UE4Editor]
-[FCocoaGameThread main] Address = 0x10ad13fc1 (filename not found) [in UE4Editor-Core.dylib]
Unknown() Address = 0x7ff8095442d9 (filename not found) [in Foundation]
_pthread_start Address = 0x7ff80861f4f4 (filename not found) [in libsystem_pthread.dylib]
thread_start Address = 0x7ff80861b00f (filename not found) [in libsystem_pthread.dylib]

```

---

<div class="post-metadata">

**Author:** ![UE\_FlavienP](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ue_flavienp/32/1194546_2.png) [@UE\_FlavienP](https://forums.unrealengine.com/u/UE_FlavienP)\
**Post date:** [May 30, 2022, 7:16pm UTC](https://forums.unrealengine.com/t/trouble-exporting-in-gltf-using-python/564897/2 "2022-05-30T19:16:03Z")

</div>

In the past I was not specifying the “task.exporter” and I was just letting the task figure it out based on extension.

```auto
    task = unreal.AssetExportTask()
    # this could be just one asset if you only want to export one single asset
    task.object = selected_actors[0].get_world()
    task.filename = output_file
    task.selected = True
    task.prompt = False
    task.automated = True
    task.options = unreal.GLTFExportOptions()
    unreal.Exporter.run_asset_export_task(task)

```

If you updated the glTF plugin to version 1.3.0 you should be able to use a function that wraps around the task like this:

```auto
unreal.GLTFExporter.export_to_gltf()

```

e.g.:

```auto
import unreal

assetPath = '/GLTFExporterTests/Models/'
outputDir = 'c:/Temp/glTFExport/'
glTFExportOptions = unreal.GLTFExportOptions()
glTFExportOptions.export_vertex_colors = True
selectedActors = set()

staticMeshPaths = unreal.EditorAssetLibrary.list_assets(assetPath)
for smp in staticMeshPaths:
    sm = unreal.EditorAssetLibrary.load_asset(smp)
    if unreal.MathLibrary.class_is_child_of(sm.get_class(), unreal.StaticMesh):
        print(smp)
        exportpath = outputDir+sm.get_name()+'/'+sm.get_name()+'.gltf'
        unreal.GLTFExporter.export_to_gltf(sm,exportpath,glTFExportOptions,selectedActors)

```
