2011-07-17 13:29:50 +00:00
|
|
|
# exports each selected object into its own file
|
|
|
|
|
|
|
|
import bpy
|
|
|
|
import os
|
|
|
|
|
|
|
|
# export to blend file location
|
|
|
|
basedir = os.path.dirname(bpy.data.filepath)
|
|
|
|
|
|
|
|
if not basedir:
|
|
|
|
raise Exception("Blend file is not saved")
|
|
|
|
|
2018-07-24 09:18:45 +00:00
|
|
|
view_layer = bpy.context.view_layer
|
2014-09-21 03:16:24 +00:00
|
|
|
|
2018-07-24 09:18:45 +00:00
|
|
|
obj_active = view_layer.objects.active
|
2011-07-17 13:29:50 +00:00
|
|
|
selection = bpy.context.selected_objects
|
|
|
|
|
|
|
|
bpy.ops.object.select_all(action='DESELECT')
|
|
|
|
|
|
|
|
for obj in selection:
|
|
|
|
|
2018-11-07 21:51:03 +00:00
|
|
|
obj.select_set(True)
|
2011-07-17 13:29:50 +00:00
|
|
|
|
2014-09-21 03:16:24 +00:00
|
|
|
# some exporters only use the active object
|
2018-07-24 09:18:45 +00:00
|
|
|
view_layer.objects.active = obj
|
2014-09-21 03:16:24 +00:00
|
|
|
|
2011-07-17 13:29:50 +00:00
|
|
|
name = bpy.path.clean_name(obj.name)
|
|
|
|
fn = os.path.join(basedir, name)
|
|
|
|
|
|
|
|
bpy.ops.export_scene.fbx(filepath=fn + ".fbx", use_selection=True)
|
|
|
|
|
2018-06-26 17:41:37 +00:00
|
|
|
# Can be used for multiple formats
|
2011-07-17 13:29:50 +00:00
|
|
|
# bpy.ops.export_scene.x3d(filepath=fn + ".x3d", use_selection=True)
|
|
|
|
|
2018-11-07 21:51:03 +00:00
|
|
|
obj.select_set(False)
|
2011-07-29 01:24:03 +00:00
|
|
|
|
2011-07-17 13:29:50 +00:00
|
|
|
print("written:", fn)
|
|
|
|
|
2014-09-21 03:16:24 +00:00
|
|
|
|
2018-07-24 09:18:45 +00:00
|
|
|
view_layer.objects.active = obj_active
|
2014-09-21 03:16:24 +00:00
|
|
|
|
2011-07-17 13:29:50 +00:00
|
|
|
for obj in selection:
|
2018-11-07 21:51:03 +00:00
|
|
|
obj.select_set(True)
|