# Batch translate Solidworks Headlessly via Python

**URL:** <https://forums.unrealengine.com/t/batch-translate-solidworks-headlessly-via-python/116024>\
**Category:** Pipeline & Plugins\
**Tags:** Datasmith, unreal-engine\
**Created:** [September 7, 2018, 6:18pm UTC](https://forums.unrealengine.com/t/batch-translate-solidworks-headlessly-via-python/116024 "2018-09-07T18:18:17Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Ro-Su](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ro-su/32/694091_2.png) [@Ro-Su](https://forums.unrealengine.com/u/Ro-Su)\
**Post date:** [September 10, 2018, 9:14pm UTC](https://forums.unrealengine.com/t/batch-translate-solidworks-headlessly-via-python/116024/5 "2018-09-10T21:14:18Z")

</div>

Hey,  
I just worked up a proof of concept. When I run this with the -ExecutePythonScript flag, I get a single FBX exported for my assembly.

Hopefully this looks pretty straightforward. Let me know if you have questions.

```auto

import unreal

file_to_import = "D:\\assets\\CAD\\Mage-Bike\\Clutch assembly.SLDASM"
final_fbx_file = "D:\\my_filename.fbx"

# clear anything existing in the level.
all_actors = unreal.EditorLevelLibrary.get_all_level_actors()

for a in all_actors:
    unreal.EditorLevelLibrary.destroy_actor(a)

# Construct the Datasmith Scene from a file on disk.
ds_scene_in_memory = unreal.DatasmithCADSceneElement.construct_datasmith_scene_from_file(file_to_import, "/Game/MyCADScene")

print("constructed the scene")

if ds_scene_in_memory is None:
    print "Scene loading failed."
    quit()

# Set import options.
import_options = ds_scene_in_memory.get_import_options()
tessellation_options = import_options.tessellation_options
tessellation_options.chord_tolerance = 15
tessellation_options.max_edge_length = 40
tessellation_options.normal_tolerance = 45
base_options = import_options.base_options
base_options.scene_handling = unreal.DatasmithImportScene.CURRENT_LEVEL

# Finalize the process by creating assets and actors.
ds_scene_in_memory.import_scene()

# Clean up the Datasmith Scene.
ds_scene_in_memory.destroy_scene()

print("Import complete!")

# merge the actors into one object
all_actors = unreal.EditorLevelLibrary.get_all_level_actors()
merge_options = unreal.EditorScriptingMergeStaticMeshActorsOptions()
# look for the unreal.MeshMergingSettings class to see what options you can set in here
merge_options.base_package_name = "/Game/NEW_MESH"
new_mesh_actor = unreal.EditorLevelLibrary.merge_static_mesh_actors(all_actors, merge_options)

# load the merged asset
loaded_asset = unreal.EditorAssetLibrary.load_asset("/Game/NEW_MESH")

# set up the FBX export options
task = unreal.AssetExportTask()
task.object = loaded_asset # the asset to export
task.filename = final_fbx_file # the filename to export as
task.automated = True # don't display the export options dialog
task.replace_identical = True # always overwrite the output
task.options = unreal.FbxExportOption()

# export!
result = unreal.Exporter.run_asset_export_task(task)

print("Export complete!")
for error_msg in task.errors:
    unreal.log_error("{}".format(error_msg))

```

---

_[View the full topic](https://forums.unrealengine.com/t/batch-translate-solidworks-headlessly-via-python/116024)._
