Hi
So we exported animation for Unity using the Game Exporter. We created animation clips so Unity can read the clips.
Now I'm writing a script that will reexport the FBX's, but I need to retrieve the Animation Clips from the old FBXs.
I'd like to import the old FBX, Check the names of the animation clips, set the animation clips, and reexport.
This I'm automating in python. The only thing I can't seem to get right is accessing the animation clip name from the FBX. The Animation Clips shows up perfectly fine in Unity, so they are definitely set.
Solved! Go to Solution.
Solved by kevinvandecar. Go to Solution.
Hi,
There is a good topic in the help about working with animation: http://help.autodesk.com/view/FBX/2019/ENU/?guid=FBX_Developer_Help_animation_extracting_animation_d...
Note that the key ideas are to work with the animation stacks and then the animation layers in each stack. Although I am not a python expert, I can see the important objects have equivalent python bindings, so I think you should be able to accomplish the same techniques in python.
hope it helps,
kevin
I have actually solved it myself, and wrote a python script to get the clips from an FBX file without importing it.
Example:
get_clips_from_FBX( 'c:\fbx_files\fbx_file.fbx', 1)
The 1 as the second argument will print out the results.
This code will return all the animation clips in an FBX and their time values.
Please note that Maya sometimes refers to animation clips as 'takes'.
Reference:
https://knowledge.autodesk.com/support/maya/learn-explore/caas/CloudHelp/cloudhelp/2016/ENU/Maya/fil...
import maya.cmds as cmds
import maya.mel as mel
def get_clips_from_FBX( FBX_file, print_results=0 ):
#read the FBX_file
mel.eval('FBXRead -f "' + FBX_file + '"' )
#get the amount of clips in FBX_file
FBXTakeCount = mel.eval('FBXGetTakeCount')
#get the clip_names from FBX_file
clip_name_time = []
for i in range(FBXTakeCount):
#convert integer into string for MEl command
strI = str(i+1)
#get the clip_name from FBX
clip_name = mel.eval('FBXGetTakeName ' + strI)
#get the clip_time from FBX
clip_time = mel.eval('FBXGetTakeLocalTimeSpan ' + strI)
#put the clip_name and clip_time in clip_name_time variable for return
clip_name_time.append(clip_name)
clip_name_time.append(clip_time)
if print_results:
print( '\n' + strI + '.) Clip Name: ' + clip_name )
print( strI + '.) Clip Time: ' + str(clip_time) + '\n')
#close the FBX file
mel.eval('FBXClose' )
return(clip_name_time)
Can't find what you're looking for? Ask the community or share your knowledge.