Download

Help in Python Scripting to Import a Gltf Model

Hey, experts
I am trying to import a GLTF model through python scripting in content browser in an specific folder but i am getting error every time i run the script

Python Script:

from os import path
import unreal

unreal.log("Creating Folder")
localfilePath=r"D:\Valorant_map_exporter\Test.gltf"
assetGamePath="/game/triad_art/"
assetName=path.splitext(path.basename(localfilePath))[0]
content_name="Light"
content_path=assetGamePath+content_name
#Content
unreal.EditorAssetLibrary.make_directory(content_path)
unreal.log(print(content_path))


task = unreal.AssetImportTask()
task.filename= localfilePath
task.destination_name=assetName
task.destination_path= assetGamePath
task.replace_existing = True
task.automated=True
task.save=True
#task.factory=unreal.DatasmithGLTFImportOptions()


task.options=unreal.GLTFImportFactory()
#task.options.Import_Uniform_Scale=100.0
#task.options.generate_lightmap_u_vs = False
#task.options.include_animation=True
#task.options.Lights=False
#task.options.Cameras=False
#task.options.Animation=False

unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task])
importedAssets = task.get_editor_property('imported_object_paths')
if not importedAssets:unreal.log_error('Failed to import {0}'.format(localfilePath))
else: unreal.log('Sucessfully Imported {0}'.format(localfilePath))

Error That I get :

Cmd: py "D:/Valorant_map_exporter/Unreal Scripting/Test.py"
LogPython: Creating Folder
LogPython: /game/triad_art/Light
LogPython: None
LogSlate: Took 0.000394 seconds to synchronously load lazily loaded font '../../../Engine/Content/Slate/Fonts/Roboto-Light.ttf' (167K)
LogFactory: FactoryCreateFile: StaticMesh with GLTFImportFactory (0 0 D:\Valorant_map_exporter\Test.gltf)
D:\Valorant_map_exporter\Test.gltf
LogSlate: Warning: A modal window tried to take control while running in unattended script mode. The window was canceled.
LogStats: FPlatformStackWalk::StackWalkAndDump -  3.124 s
LogOutputDevice: Error: === FDebug::DumpStackTrace(): ===
LogOutputDevice: Error: [Callstack] 0x00007ff9d8b9ccba UE4Editor-Slate.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9a6d22867 UE4Editor-GLTFImporter.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9a6d1fe6a UE4Editor-GLTFImporter.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9c354c0b1 UE4Editor-UnrealEd.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9bbb57c16 UE4Editor-AssetTools.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9bbb54a59 UE4Editor-AssetTools.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9bbbbd2ca UE4Editor-AssetTools.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9d3ef2604 UE4Editor-CoreUObject.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9d4180e63 UE4Editor-CoreUObject.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9aca17ea1 UE4Editor-PythonScriptPlugin.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9ac9f967f UE4Editor-PythonScriptPlugin.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9ac9f8e7a UE4Editor-PythonScriptPlugin.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9ac9fa035 UE4Editor-PythonScriptPlugin.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9ac9aab4c UE4Editor-PythonScriptPlugin.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9ba00f2b6 python37.dll!_PyObject_FastCallKeywords() [c:\a\18\s\objects\call.c:199]
LogOutputDevice: Error: [Callstack] 0x00007ff9ba00dc3b python37.dll!call_function() [c:\a\18\s\python\ceval.c:4619]
LogOutputDevice: Error: [Callstack] 0x00007ff9ba0153b8 python37.dll!_PyEval_EvalFrameDefault() [c:\a\18\s\python\ceval.c:3095]
LogOutputDevice: Error: [Callstack] 0x00007ff9ba00e3ac python37.dll!_PyEval_EvalCodeWithName() [c:\a\18\s\python\ceval.c:3930]
LogOutputDevice: Error: [Callstack] 0x00007ff9ba01b573 python37.dll!PyEval_EvalCodeEx() [c:\a\18\s\python\ceval.c:3966]
LogOutputDevice: Error: [Callstack] 0x00007ff9ba01b4d1 python37.dll!PyEval_EvalCode() [c:\a\18\s\python\ceval.c:530]
LogOutputDevice: Error: [Callstack] 0x00007ff9ac9b0395 UE4Editor-PythonScriptPlugin.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9ac9e1efd UE4Editor-PythonScriptPlugin.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9ac9b0950 UE4Editor-PythonScriptPlugin.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9ac9b07fa UE4Editor-PythonScriptPlugin.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9ac9b0716 UE4Editor-PythonScriptPlugin.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9d4b91000 UE4Editor-Core.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9d40e1d47 UE4Editor-CoreUObject.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9c5dd4c2a UE4Editor-Engine.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9c33fb448 UE4Editor-UnrealEd.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9c3c7db77 UE4Editor-UnrealEd.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9ac9c6cda UE4Editor-PythonScriptPlugin.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9ac9b1021 UE4Editor-PythonScriptPlugin.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9d8c9ee15 UE4Editor-Slate.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9d8ca5600 UE4Editor-Slate.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9d8c7b807 UE4Editor-Slate.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9d8d1859e UE4Editor-Slate.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9d8d3071e UE4Editor-Slate.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9d8ca6d75 UE4Editor-Slate.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9d8b746be UE4Editor-Slate.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9d8bf7f14 UE4Editor-Slate.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9d8be0337 UE4Editor-Slate.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff9d8bd3632 UE4Editor-Slate.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ffa1de4bcb5 UE4Editor-ApplicationCore.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ffa1de39197 UE4Editor-ApplicationCore.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ffa1de4e389 UE4Editor-ApplicationCore.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ffa1de34310 UE4Editor-ApplicationCore.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ffa358fe858 USER32.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ffa358fe299 USER32.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ffa1de4f914 UE4Editor-ApplicationCore.dll!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff7df748848 UE4Editor.exe!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff7df76117c UE4Editor.exe!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff7df76125a UE4Editor.exe!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff7df7752bd UE4Editor.exe!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ff7df777fea UE4Editor.exe!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ffa34317034 KERNEL32.DLL!UnknownFunction []
LogOutputDevice: Error: [Callstack] 0x00007ffa35f62651 ntdll.dll!UnknownFunction []
LogAssetTools: The import task was canceled.
LogFileHelpers: No new changes to save!
LogPython: Error: Failed to import D:\Valorant_map_exporter\Test.gltf

please tell me how i can fix this error…:slight_smile:

Hello,

there are two plugins to import gltf: the gltf importer and Datasmith gltf importer. The datasmith one leverage the gltf importer and do some extra stuff on import. I believed they will be merged in the future.

Your approach looks good, and would rely on the gltf importer route. I am not sure why it is failing, I did repro on my machine. When I tried to force the factory it also failed with a different message.

What I managed to do and I can propose to you is to go the datasmith route:

from os import path
import unreal

unreal.log("Creating Folder")
localfilePath=r"D:\Valorant_map_exporter\Test.gltf"
assetGamePath="/game/triad_art/"
assetName=path.splitext(path.basename(localfilePath))[0]
content_name="Light"
content_path=assetGamePath+content_name
#Content
unreal.EditorAssetLibrary.make_directory(content_path)
unreal.log(print(content_path))
 
datasmith_scene = unreal.DatasmithSceneElement.construct_datasmith_scene_from_file(localfilePath)
 
# set import options
import_options = datasmith_scene.get_options()
import_options.base_options.scene_handling = unreal.DatasmithImportScene.CURRENT_LEVEL
 
 
result = datasmith_scene.import_scene(assetGamePath)
 
print (result.import_succeed)
1 Like

Thanks for this I had already switched to datasmith one , I have one more issue if you can help me I wanna import a mesh from the content browser to the current level how I can do that with python?

Basically you just have to do:

path_asset_in_content_browser = "/game/..."
loaded_asset = unreal.EditorAssetLibrary.load_asset(path_asset_in_content_browser)
spawn_location = unreal.Vector()
spawn_orientation = unreal.Rotator()
unreal.EditorLevelLibrary.spawn_actor_from_object(loaded_asset, spawn_location, spawn_orientation)

You can find some other samples here GitHub - ue4plugins/PythonSamples

1 Like