MotionBuilder Forum
Welcome to Autodesk’s MotionBuilder Forums. Share your knowledge, ask questions, and explore popular MotionBuilder topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Retargeting with Python

17 REPLIES 17
Reply
Message 1 of 18
cmptrartist
1901 Views, 17 Replies

Retargeting with Python

I've been trying to work on a way of doing a batch retarget, but no luck. As best I can tell, the function for FBFbxManager that does this is only avaliable through the UI and not avaliable through Python. Can anyone verify this? The best I can do is import the animation and then have it drive the original character. From there I can bake it out. Something like this:

def importRetargetAnimation(importFileName):

lScene = FBSystem().Scene
charactersList = lScene.Characters
myChar = charactersList

myPlotOptions = SetPlotToCtrlRigOptions()

FBFbxManagerLoadAnimationMethod.kFBFbxManagerLoadRetarget

manager = FBFbxManager()
manager.LoadBegin(importFileName, True)


#this is the function that is only avaliable through the API
#manager.LoadAnimationOnCharacter(importFileName, myChar, 0, 0, 1, 1, FBFbxManagerLoadAnimationMethod.kFBFbxManagerLoadRetarget, myPlotOptions, 0, 1, 0)


manager.Lights = FBElementAction.kFBElementActionDiscard
manager.Materials = FBElementAction.kFBElementActionDiscard
manager.CharactersAnimation = FBAnimationAction.kFBAnimationActionConsider
manager.Load()
manager.LoadEnd()

charactersList = lScene.Characters

for char in charactersList:
if char != myChar:
myChar.InputCharacter = char
myChar.InputType = FBCharacterInputType.kFBCharacterInputCharacter
myPlotOptions = SetPlotToSkeletonOptions()
myChar.PlotAnimation(FBCharacterPlotWhere.kFBCharacterPlotOnSkeleton, myPlotOptions )

for char in charactersList:
if char != myChar:
FBComponent.FBDelete(char)



Anyway, I'm really green when it comes to Motionbuilder, so any help would be appreciated.
17 REPLIES 17
Message 2 of 18
_KxL_
in reply to: cmptrartist

Also can't see LoadAnimationOnCharacter in python, but what is wrong with manually import and plot?
Message 3 of 18
cmptrartist
in reply to: cmptrartist

The problem with doing it manually is 1) I have to do it to about 100 files, and 2) since my predecessors didn't use Motionbuilder correctly a simple one-time plot won't work, so I have to juggle the data between multiple rigs to get it correct. I have a kind-of sort-of batch script working, but now I'm just trying to clean it up and optimize it.
Message 4 of 18
_KxL_
in reply to: cmptrartist

Guess I will need to take a closer look at this, and will do it when find a little time.

Cheers
Message 5 of 18
cmptrartist
in reply to: cmptrartist

Thanks, I appreciate it. As I said, I have something cobbled together, but it's messy. I'd rather figure out the right way to do it. Right now I'm trying to figure out how to clean up after myself with this thing
Message 6 of 18
Anonymous
in reply to: cmptrartist

Hi cmptrArtist,

Have you try to go through the Load Character Animation tool in the character control. This is a tool that already batch character animation. You just need to set the way you want to retarget that.

You wont find that in the documentation...;)

FBFbxManager().LoadAnimationOnCharacter(str pFileName, FBCharacter pCharacter, bool pReplaceRig, bool pCopyMissingExtensions, bool pUpdateLimits, bool pIgnoreConflicts, FBFbxManagerLoadAnimationMethod pTransferMethod, FBPlotOptions pPlotOptions, bool pProcessAnimationOnExtensions, bool pRetargetOnBaseLayer, bool pResetHierarchy);



And this is to use the Save Character Animation in the Character Control:

FBFbxManager().SaveCharacterRigAndAnimation( char* pFileName, HFBCharacter pCharacter, bool pSaveCharacter, bool pSaveRig, bool pSaveExtensions )


Hope this helps,

Mart
Message 7 of 18
_KxL_
in reply to: cmptrartist

Thanks Mart for correcting me, I was writing this in hurry, you are absolutely right!

Cheers
Message 8 of 18
cmptrartist
in reply to: cmptrartist

Actually, I tried that, couldn't get it to work

I must be doing something wrong, because when I try it I get :

AttributeError: `FBFbxManager` object has no attribute `LoadAnimationOnCharacter`
Message 9 of 18
Anonymous
in reply to: cmptrartist

Here's an exemple of how I use it, and it work for me:



FBFbxManager().LoadAnimationOnCharacter(r'C:\mpigeon\PythonScript\Python_Script_Examples\PythonTest_LoadCharacterAnime\Motions\A_Car.fbx', Character, False, False, False, True, FBFbxManagerLoadAnimationMethod().kFBFbxManagerLoadRetarget, OptionsA, False, False, False);




Are you using MB752? Because Im not sure it is working in the other version....
Message 10 of 18
cmptrartist
in reply to: cmptrartist

That actually explains a bit. I'm on 7.5 extension 1
Message 11 of 18
Anonymous
in reply to: cmptrartist

Did anybody ever get this to work?

I've been trying to figure out how to batch retarget characters for a while, and a tool like that could *really* save my ass.

Thanks!

-jb
Message 12 of 18
_KxL_
in reply to: cmptrartist

FBFbxManager().LoadAnimationOnCharacter(...) is not working for you? Which MB version are you using?
Message 13 of 18
Anonymous
in reply to: cmptrartist

Sorry to bring back an old topic - but I'm new to Python and I'm having trouble with this also.

I'm using MB2010 and I can't get the LoadAnimationOnCharacter to work. I'm using it like this:

lMgr.LoadAnimationOnCharacter(lFp.Path + "\\" + fname, lScene.Characters, False, False, False, True, FBFbxManagerLoadAnimationMethod().kFBFbxManagerLoadRetarget, None, False, True, False )


But I always get the following error:

Boost.Python.ArgumentError: Python argument types in
FBFbxManager.LoadAnimationOnCharacter(FBFbxManager, str, FBCharacter, bool, bool, bool, bool, FBFbxManagerLoadAnimationMethod, NoneType, bool, bool, bool)
did not match C++ signature:
LoadAnimationOnCharacter(class PYFBSDK::FBFbxManager_Wrapper {lvalue}, char *, class PYFBSDK::FBCharacter_Wrapper {lvalue}, bool, bool, bool, bool, enum ORSDK80_RC1::FBFbxManagerLoadAnimationMethod, class PYFBSDK::FBPlotOptions_Wrapper {lvalue}, bool, bool, bool)


Am I making a really simple mistake?
Message 14 of 18
Anonymous
in reply to: cmptrartist

funny enough i'm working on a batch script as well and am having the same issue. double checked the parameters that i am passing and i think that they should all be fine... but i get the same error that you do. strange.
Message 15 of 18

I haven't tested this, but from what I see the problem is this:


FBFbxManagerLoadAnimationMethod().kFBFbxManagerLoadRetarget



This is an enumerator, so you don't call it like a function, you use it like this:


FBFbxManagerLoadAnimationMethod.kFBFbxManagerLoadRetarget



So the line would be:

lMgr.LoadAnimationOnCharacter(lFp.Path + "\\" + fname, lScene.Characters, False, False, False, True, FBFbxManagerLoadAnimationMethod.kFBFbxManagerLoadRetarget, None, False, True, False )


Stev
Message 16 of 18
Anonymous
in reply to: cmptrartist

FBFbxManager is deprecated, supposed to use FBapplication now.


I can get this to work:

pFileName = r'C:/myPathToImportFile'
pCharacter = FBApplication().CurrentCharacter
pFbxOptions = FBFbxOptions(1)
pPlotOptions = FBPlotOptions()
app = FBApplication()
app.LoadAnimationOnCharacter(pFileName, pCharacter, pFbxOptions, pPlotOptions)



but it leaves the UI up, I have to click the 'Open' button on the UI to complete the task. Anybody know how to get this command to complete?

Thanks,
Message 17 of 18
Anonymous
in reply to: cmptrartist

FYI, My buddy pointed me to this answer:
pFbxOptions.ShowOptionsDialog = False
Message 18 of 18
Anonymous
in reply to: cmptrartist

Hi,

 

I was wondering how to choose which character animation to load if the animation file has mulltiple character animation?

Is it possible to do it through LoadAnimationOnCharacter()?

 

Thanks.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report