Give this a go, I wrote it for someone as a favour;
#!/usr/bin/env python
import lx
import os
# Check if the scene has been saved.
scene_changed = lx.eval1 ('query sceneservice scene.changed ? current')
lx.eval ('dialog.setup saveOK')
lx.eval ('dialog.title "Scene Unsaved"')
lx.eval ('dialog.msg "The scene has not been saved. Any errors might result in unsaved work being lost. Save before exporting?"')
try:
lx.eval ('dialog.open')
except:
pass
save_result = lx.eval1 ('dialog.result ?')
# User didn't hit cancel.
if save_result != 'cancel':
# User asked to save the scene first.
if save_result == 'ok':
lx.eval ('!scene.save')
# Get the directory to export to.
lx.eval ('dialog.setup dir')
lx.eval ('dialog.title "Export Path"')
lx.eval ('dialog.msg "Select path to export to."')
try:
lx.eval ('dialog.open')
except:
pass
else:
output_dir = lx.eval1 ('dialog.result ?')
# Get the current FBX Export setting.
fbx_export_setting = lx.eval1 ('user.value sceneio.fbx.save.exportType ?')
# Set the FBX Export setting to export selection.
lx.eval ('user.value sceneio.fbx.save.exportType FBXExportSelection')
# Replace the above line with this if you want selection & hierarchy.
# lx.eval ('user.value sceneio.fbx.save.exportType FBXExportSelectionWithHierarchy')
# Grab the IDs of each foreground layer.
layers = lx.evalN ('query layerservice layer.id ? fg')
# Export each layer separately.
for layer in layers:
# Get the layer name.
layer_name = lx.eval1 ('query layerservice layer.name ? %s' % layer)
# Work out the export path from the name.
output_path = os.path.join (output_dir, layer_name + '.fbx')
# Select only the mesh item.
lx.eval ('select.subItem %s set mesh' % layer)
# Export to FBX.
lx.eval ('!scene.saveAs "%s" fbx true' % output_path)
# Reselect the layers the user had selected.
lx.eval ('select.subItem %s set mesh' % layer)
for layer in layers:
lx.eval ('select.subItem %s add mesh' % layer)
# Put the user's original FBX Export setting back.
lx.eval ('user.value sceneio.fbx.save.exportType %s' % fbx_export_setting)
Hi James, I've been using this script for a while now, it saves me so much time! For some reasons though sometimes it will fail to place the meshes on 0,0,0 when it's doing the 'export every mesh item' line (I think), any clue as to why? For example, I have 3 mesh items here with item centers snapped to place for the pivot (using another script from you :]). But When I batch FBX export I get undesired result in engine.
Here's the properties of the wall only (white mesh item above)
I'm not sure what I did to cause this to happen, I've tried freezing everything, re-setting the centers and export again, but I'm still getting the same result in engine.
*EDIT: I copied the polygons of each mesh item and placed into newly created item layers and behold, it's working now! I've absolutely no idea what I did to the meshes so it didn't work, maybe there is a way to ensure it won't happen in the script?
Replies
Give this a go, I wrote it for someone as a favour;
Fixed the links in the 1st post.
For some reasons though sometimes it will fail to place the meshes on 0,0,0 when it's doing the 'export every mesh item' line (I think), any clue as to why?
For example, I have 3 mesh items here with item centers snapped to place for the pivot (using another script from you :]). But When I batch FBX export I get undesired result in engine.
Here's the properties of the wall only (white mesh item above)
I'm not sure what I did to cause this to happen, I've tried freezing everything, re-setting the centers and export again, but I'm still getting the same result in engine.
*EDIT: I copied the polygons of each mesh item and placed into newly created item layers and behold, it's working now! I've absolutely no idea what I did to the meshes so it didn't work, maybe there is a way to ensure it won't happen in the script?