From BlenderWiki
< Extensions:Py | Scripts | Manual | Export | FBX
#!/bin/bash # See bottom of the file for export options BLENDER_BIN=blender BLEND=$1 FBX=$2 # check we have blender installed if hash $BLENDER_BIN 2>/dev/null; then # do nothing echo $BLENDER_BIN "found in path..." else echo $BLENDER_BIN "is not in the path, aborting!" exit 1 fi if [ $# -ne 2 ] ; then echo "Expected 2 arguments!" echo "Usage: convertBlendToFbx.sh from.blend to.fbx" exit 1 fi if ! [ -e $BLEND ]; then echo "Blend file" $BLEND "does not exist, aborting!" exit 1 fi # Temp Py file. TEMP_PY=`mktemp` touch $TEMP_PY # Add contense to the temp file echo "fbx_file ='"$FBX"'" >> $TEMP_PY cat >> $TEMP_PY << EOF import Blender import sys try: import export_fbx except: print 'error: export_fbx.py not found.' Blender.Quit() # See the fbx exporter for some more options export_fbx.write(fbx_file,\ EXP_OBS_SELECTED=False,\ EXP_MESH=True,\ EXP_MESH_APPLY_MOD=True,\ EXP_MESH_HQ_NORMALS=True,\ EXP_ARMATURE=True,\ EXP_LAMP=True,\ EXP_CAMERA=True,\ EXP_EMPTY=True,\ EXP_IMAGE_COPY=True,\ ANIM_ENABLE=True,\ ANIM_OPTIMIZE=True,\ ANIM_ACTION_ALL=True,\ GLOBAL_MATRIX = Blender.Mathutils.RotationMatrix( -90, 4, 'x' ),\ ) Blender.Quit() EOF # Run blender echo $BLEND $BLENDER_BIN $BLEND -P $TEMP_PY rm $TEMP_PY echo "finished command line conversion!"
[edit] Converting with Rotation
If you need to export with some transformation, you can do this by setting passing the GLOBAL_MATRIX variable to export_fbx.write()
The GLOBAL_MATRIX (example shows a rotation matrix, but you can use any matrix, change the values for the transformation you desire)...
GLOBAL_MATRIX = Blender.Mathutils.Matrix([1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]),\
If you'd rather not enter in the exact matrix you can use a function to create a rotation matrix...
GLOBAL_MATRIX = Blender.Mathutils.RotationMatrix( -90, 4, 'x' ),\
or multiply them...
GLOBAL_MATRIX = Blender.Mathutils.RotationMatrix( -90, 4, 'x' ) * Blender.Mathutils.RotationMatrix( 180, 4, 'z' ),\
Note, some applications will raise errors when bones are scaled (Maya, 3dsMax and Lightwave. so its best only to use a rotation/translation matrix)
See the RotationMatrix documentation.







![[]](/skins/blender/open.png)
