## **伍、整合**
**H子:** 好的老師,等我自己來完整的設計一次代碼吧,你只要看著我就行了。
**AOI:** 這么主動?真少見呢。
**H子:** 哼哼,條件已經齊備,我非常信心一口氣的搞定。看我的:
~~~python
import bpy
#定義導出路徑
savePath = "c:/tmp/TestExport/"
#保存選中對象
objs = bpy.context.selected_objects
print(objs)
#遍歷
for o in objs:
#清除全選并按名稱選中對象
bpy.ops.object.select_all(action='DESELECT')
bpy.data.objects[o.name].select = True
#保存清零變換前的對象變換參數
s_Locx = bpy.data.objects[o.name].location.x
s_Locy = bpy.data.objects[o.name].location.y
s_Locz = bpy.data.objects[o.name].location.z
s_rotx = bpy.data.objects[o.name].rotation_euler.x
s_roty = bpy.data.objects[o.name].rotation_euler.y
s_rotz = bpy.data.objects[o.name].rotation_euler.z
s_scax = bpy.data.objects[o.name].scale.x
s_scay = bpy.data.objects[o.name].scale.y
s_scaz = bpy.data.objects[o.name].scale.z
#清零變換
bpy.ops.object.location_clear(clear_delta=False)
bpy.ops.object.scale_clear(clear_delta=False)
bpy.ops.object.rotation_clear(clear_delta=False)
#導出模型
bpy.ops.export_scene.fbx(filepath=savePath + o.name + ".fbx",axis_forward='-Z', axis_up='Y',version='BIN7400',use_selection=True,bake_space_transform=True, object_types={'MESH'})。
#還原模型變換
bpy.data.objects[o.name].location.x = s_Locx
bpy.data.objects[o.name].location.y = s_Locy
bpy.data.objects[o.name].location.z = s_Locz
bpy.data.objects[o.name].rotation_euler.x = s_rotx
bpy.data.objects[o.name].rotation_euler.y = s_roty
bpy.data.objects[o.name].rotation_euler.z = s_rotz
bpy.data.objects[o.name].scale.x = s_scax
bpy.data.objects[o.name].scale.y = s_scay
bpy.data.objects[o.name].scale.z = s_scaz
~~~
全選模型之后執行,成功的在目標文件夾導出了模型
