import bpy
import sys
from mathutils import Vector
# Grab command line arguments
argv = sys.argv
fbx = argv[argv.index("--") + 1]
tgt = argv[argv.index("--") + 2]
print("Importing from ", fbx, " and Exporting to ", tgt)
# Deletes the whole object hierarchy
def delete_hierarchy(obj):
names = set([obj.name])
# Recursively grab object names
def get_child_names(obj):
for child in obj.children:
names.add(child.name)
if child.children:
get_child_names(child)
# Call the recursive function
get_child_names(obj)
# Delete the objects
for n in names :
bpy.data.objects.remove(bpy.data.objects[n], True)
# Import FBX
bpy.ops.import_scene.fbx( filepath = fbx )
# Grab the new armature and scale it.
new_armature = bpy.data.objects['Armature.001']
new_armature.scale = Vector( (0.013, 0.013, 0.013) )
# Make sure the armature has animation data
if new_armature.animation_data == None :
new_armature.animation_data_create()
# Grab the new animation
new_armature_animation = new_armature.animation_data
# Grab the old armature
old_armature = bpy.data.objects['Armature']
old_armature_animation = old_armature.animation_data
# Get the properties of the old animation
properties = [p.identifier for p in old_armature_animation.bl_rna.properties if not p.is_readonly]
# Copy all animation properties
for prop in properties:
setattr(new_armature_animation, prop, getattr(old_armature_animation, prop))
# Delete the old object
delete_hierarchy(old_armature)
# Rename the new object
new_armature.name = 'Armature'
# Save the new file
bpy.ops.wm.save_as_mainfile( filepath = tgt )