Loading Character Animation through python

Loading Character Animation through python

vdebaie
Advocate Advocate
3,075 Views
6 Replies
Message 1 of 7

Loading Character Animation through python

vdebaie
Advocate
Advocate

I'm trying to figure out how to use python to load character animation.

 

 

 

Currently what I'm looking to do is load a Character Animation onto my rig without any pop ups and the method that is needed is to "Copy Animation (no retargetting)" and to the "Process Aniamtion" to be set to false.


I've been getting a number of different errors when i try to use FBApplication().LoadAnimationOnCharacter and I can't seem to figure out how to use FBCharacterLoadAnimationMethod.kFBCharacterLoadCopy.

Any help would be greatly appreciated.

0 Likes
Accepted solutions (1)
3,076 Views
6 Replies
Replies (6)
Message 2 of 7

brissef2
Autodesk
Autodesk
Accepted solution

Hi vdebaie,

 

It looks the following code sample seem to do what you are looking for:

lFbxOptions = FBFbxOptions( True )
lFbxOptions.TransferMethod = FBCharacterLoadAnimationMethod.kFBCharacterLoadCopy
lFbxOptions.ProcessAnimationOnExtension = False

lPlotOptions = FBPlotOptions()

lAnimFile = ...
lTargetCharacter = ...

FBApplication().LoadAnimationOnCharacter( lAnimFile, lTargetCharacter, lFbxOptions, lPlotOptions )

If not, please let me know.

 

Best regards,

Francis

0 Likes
Message 3 of 7

vdebaie
Advocate
Advocate

That works! Thank you so much.

I'm trying to load a new scene and import a Character Rig and then have my animations load on to it, the problem now is the script is asking me to load the animations before the scene gets merged and i get a "no character in scene error".

The script is wrote as:

#Clear Scene and Merge in new Ctrl Rig
 
# New Scene
lfbApp.FileNew()
 
# Import our target Control rig
lfbMergeFilePath = r'the path to my CharacterRig.fbx'
 
#The name of the take used as source
lfbTakeSource = 'Take Source'
#The name of the take where the data must be imported
lfbTakeDest = 'Take 001'
 
#Init the FbxOptions
lfbMergeOptions = FBFbxOptions(True, lfbMergeFilePath)
 
#Disable base camera, camera switcher ...
lfbMergeOptions.BaseCameras = False
lfbMergeOptions.CameraSwitcherSettings = False
lfbMergeOptions.GlobalLightingSettings = False
lfbMergeOptions.CurrentCameraSettings = False
 
#Ensure that transport setting is enable. This elements contain the timeline parameters.
lfbMergeOptions.TransportSettings = False
 
#Pass thru all the takes to find the source take and change the destination and
#disable all the rest
lfbMergeTakeCount = lfbMergeOptions.GetTakeCount()
 
for i in range(lfbMergeTakeCount):
lfbMergeTakeName = lfbMergeOptions.GetTakeName(i)
if lfbMergeTakeName == lfbTakeSource:
lfbMergeOptions.SetTakeDestinationName(i, lfbTakeDest)
else:
lfbMergeOptions.SetTakeSelect(i, False)
 
#Set Name Space
lfbMergeOptions.NamespaceList = "the name space i want"
 
# Dissable merge popup window
lfbMergeOptions.ShowOptionsDialog = False
 
# Add to current scene
FBApplication().FileAppend(lfbMergeFilePath, True, lfbMergeOptions)
 
del (lfbMergeFilePath, lfbTakeSource, lfbTakeDest, lfbMergeOptions, lfbMergeTakeCount)
 
# Load Animation
 
lfbFbxOptions = FBFbxOptions( True )
lfbFbxOptions.TransferMethod = FBCharacterLoadAnimationMethod.kFBCharacterLoadCopy
lfbFbxOptions.ProcessAnimationOnExtension = False
lfbFbxOptions.ShowOptionsDialog = False
 
lfbPlotOptions = FBPlotOptions()
 
FBApplication().LoadAnimationOnCharacter( lfbSaveChrAnim, lfbApp.CurrentCharacter, lfbFbxOptions, lfbPlotOptions )

 Any help would be greatly appreciated, thank you. 

Message 4 of 7

brissef2
Autodesk
Autodesk

Hi vdebaie,

 

I don't have this issue on my side as everything works fine. 

As an example, set some of your variables in your script with the following:

 

lfbMergeFilePath = r'C:\\Program Files\\Autodesk\\MotionBuilder 2017\\Tutorials\\mia_rigged.fbx'

lfbTakeSource = 'Take 001'

lfbMergeOptions.NamespaceList = "testNS"

lfbSaveChrAnim = r'C:\\Program Files\\Autodesk\\MotionBuilder 2017\\Tutorials\walkaround.fbx'

 

Best regards,

Francis

0 Likes
Message 5 of 7

vdebaie
Advocate
Advocate
After restarting MotionBuilder the script started to work properly. 🙂

I have the load character animation pop up appear and wait for me to select "ok".

I've tried a few things but still seem to have it appear.

lOptions.ShowFileDialog= False
lOptions.ShowOptionsDialog= False

Is there something else that I'm missing?

Again, thank you so much for the help.

Learning Python is a difficult task in Mobu, but so rewarding.
Message 6 of 7

brissef2
Autodesk
Autodesk

Hi vdebaie,

 

With the script you provided, and with the few variables I set on top of it, I don't see any pop-up, do you?

 

Best regards,

Francis

0 Likes
Message 7 of 7

vdebaie
Advocate
Advocate

Yea, it should work without the pop up but I still get it. 

 

 

I have more lines of script atop of what I posted here, which may be causing problems. 

I know earlier when writing the script I caused MotionBuilder to prevent the "Load Character Animation..." pop up window from appearing all together (when clicking on the option form the character controls window) and it would stay vanished even when restarting the computer. The only way to get it back was to run part of the script again. So there is something in there that needs to be reworked(to say the least). I must of copied and pasted something from the forums that is not playing nice with what I am trying to do.

 

 

0 Likes