Unreal Python - Export Selected

I’m not sure the option that I’m missing to get the ‘Export Selected’ script that I’m writing to work. In the output log, I get ‘Warning: No exporter found for None’. Nothing happens.



def export_selected_fbx(file_path='C:\	est'):
task = unreal.AssetExportTask()
task.set_editor_property('selected', True)
task.set_editor_property('filename', file_path)
task.set_editor_property('automated', True)

fbx_options = unreal.FbxExportOption()
fbx_options.set_editor_property('collision', False)
fbx_options.set_editor_property('force_front_x_axis', False)
fbx_options.set_editor_property('level_of_detail', False)
task.set_editor_property('options', fbx_options)


result = unreal.Exporter.run_asset_export_task(task)
print 'Export Result: {}'.format(result)

I then thought of setting the exporter and it crashes unreal.


def export_selected_fbx(file_path='C:\	est'):
task = unreal.AssetExportTask()
task.set_editor_property('selected', True)
task.set_editor_property('filename', file_path)
task.set_editor_property('automated', True)
task.set_editor_property('exporter', unreal.ExporterFBX())

fbx_options = unreal.FbxExportOption()
fbx_options.set_editor_property('collision', False)
fbx_options.set_editor_property('force_front_x_axis', False)
fbx_options.set_editor_property('level_of_detail', False)
task.set_editor_property('options', fbx_options)


result = unreal.Exporter.run_asset_export_task(task)
print 'Export Result: {}'.format(result)

Any help would be appreciated.

Well, I figure out the export selected object issue. You need to pass the ‘World’ as your ‘object’. Here is the updated code to help others that may have had the same issue.



# Select your objects in the level
import unreal
def export_selected_fbx(file_path='C:\	est'):
     world = unreal.EditorLevelLibrary.get_editor_world()
     task = unreal.AssetExportTask()
     task.set_editor_property('selected', True)
     task.set_editor_property('filename', file_path)
     task.set_editor_property('automated', True)
     task.set_editor_property('object', world)

     fbx_options = unreal.FbxExportOption()
     fbx_options.set_editor_property('collision', False)
     fbx_options.set_editor_property('force_front_x_axis', False)
     fbx_options.set_editor_property('level_of_detail', False)
     task.set_editor_property('options', fbx_options)

     result = unreal.Exporter.run_asset_export_task(task)
     print 'Export Result: {}'.format(result)


4 Likes

Hi, I’ve just come across your post and it looks like the solution to my problem but I’m unable to get it to work.

I’ve tried adding it into a ‘Execute Python Script’ node inside of a EditorUtilityWidget and saving it to a .py file and running from the command bar but when I have some Static meshs selected and run the code it get:
“LogPython: Error: SyntaxError: invalid syntax (, line 18)”
and if I comment out the last line I don’t get an error but it doesn’t seem to export anything. Apologies if I’m missing something fundamentally obvious, im not a dev but trying to learn!

Ultimately, I’m trying to write a Editor Utilitiy that will batch export sections of a Datasmith import to .fbx. Everything else works but the “Export Scene” node doesn’t seem to have variables I can set then write to disk, everything I call it, it opens the dialog box for where to save the fbx’s too which is not ideal.

If yourself or the community could offer any insight about where I might be going wrong or have any advise on how I might ‘export selected’ from a Editor Utilitiy that would be greatly appreciated as it would massively speed up my workflow.

Thanks

since 4.26 we are on python 3+ so you need to put parenthesis for the print. It is a function

if you copy paste directly what Rayvneye did then your python script just define a function but does not call it.
So you need to add a line at the very end like

     result = unreal.Exporter.run_asset_export_task(task)
     print('Export Result: {}'.format(result))

export_selected_fbx("D:/temp/export.fbx")

… And its working!! :raised_hands:

I had read the pinned post regarding 4.26 & Python 3+ and briefly wondered if that had anything to do with it but as 4.26 was released Dec 20 and the thread was started Mar 21 I wrongly assumed not and dismissed it.

not calling it in Python was exactly the kind of oversight I feared I was making but im ecstatic my EditorUtility is now up and running.

@UE_FlavienP Thank you for your timely reply and kindly pointing out my error.
and
@Rayvneye Thank you for posting the updated code in the first place!

much appreciated!