|
There is a really great sample that comes with MotionBuilder called ‘SaveOneTakePerFile’, which from you description is exactly what your trying to do. Since takes are embedded in MotionBuilder you have to at least have one take per file.
In the class FBFbxManager, the UI functionality File > Save Selected > Save One Take Per File does not exist here, but you can achieve the same end by stepping through the takes in the scene and setting their attributes individually.
rom pyfbsdk import FBSystem, FBApplication, FBFbxManager
# First get some needed objects. lSystem = FBSystem()
lApplication = FBApplication()
lFileName = lApplication.FBXFileName
# We want to make sure that we have a scene with file name
# already, otherwise we might want to open a file popup.
# For now we assume that there is already a name to use as a
# base name. if lFileName.upper().endswith( '.FBX' ):
lMgr = FBFbxManager()
# Since we will need to change the current take as we
# save them, we keep the orginal take around to reset
# it afterwards.
lOriginalTake = lSystem.CurrentTake
# Iterate the list of takes.
for lTake in lSystem.Takes:
# Switch the current take to the one we want to save.
lSystem.CurrentTake = lTake
# Build the file name to use. Here we use the same pattern
# MotionBuilder would use.
lTakeFileName = "%s-%s.fbx" % ( lFileName[:-4], lTake.Name )
# Some feedback for the user...
print "Saving Take '%s' to file '%s'" % ( lTake.Name, lTakeFileName )
# Go through the actual process of saving to the file.
# WARNING: We do not do any error checking on the return
# values of SaveBegin()/Save()/SaveEnd()!!!
lMgr.SaveBegin( lTakeFileName )
# Let's save to ASCII format.
lMgr.UseASCIIFormat = True
# Go through the list of takes to export to tag only
# the correct take. All the other are disregarded.
for lTakeSave in lMgr.Takes:
if lTakeSave.Name != lTake.Name:
lTakeSave.Import = False
# Cleanup
del( lTakeSave )
lMgr.Save()
lMgr.SaveEnd()
# Cleanup.
del( lTake, lTakeFileName )
# Return the current take to the original.
lSystem.CurrentTake = lOriginalTake
del( lMgr, lOriginalTake )
else:
print 'File name does not end with ".fbx". Unable to proceed!'
# Cleanup of local variables. del( lSystem, lApplication, lFileName )
# Cleanup of imported symbols. del( FBSystem, FBApplication, FBFbxManager )
KRISTINE MIDDLEMISS | SENIOR DEVELOPER CONSULTANT
AUTODESK DEVELOPER NETWORK Media & Entertainment
http://www.autodesk.com/joinadn
|