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: 

Paste Object Poses

10 REPLIES 10
Reply
Message 1 of 11
quebrado
1117 Views, 10 Replies

Paste Object Poses

I'm trying to paste a saved skeleton pose onto an imported skeleton but am struggling to see how to use it correctly. I've been able to paste character poses onto the control rig using the following and want to do something similar:

 

cPoses = FBSystem().Scene.CharacterPoses
thePose = cPoses[0]            # the 1st pose in the list

pChar = FBSystem().Scene.Characters[0]
poseOptions = FBCharacterPoseOptions()
thePose.PastePose(pChar, poseOptions)

Using:

poses = FBSystem().Scene.ObjectPoses
poseOptions = FBObjectPoseOptions()

objectPose = poses[0]

 

...but now I can't figure how to use PasteObjectPose or PasteTransform correctly; I'm getting errors whatever I feed them. Can I paste the pose onto all of the bones at once or must I do it on an array of all the bones in the hierarchy contained in the pose, got using say FBGetSelectedModels()?

10 REPLIES 10
Message 2 of 11
quebrado
in reply to: quebrado

Just to clarify further (as reading my post back it's not entirley clear), I am trying to paste a pose onto a skeleton before it has been characterized or had any control rig applied.

Message 3 of 11

You would have to grab the selection of the skeleton and create the pose from that selection, then paste instead of getting the character nodes.

Message 4 of 11

Have the same issue. I have skeleton and pose for it, but i don't get how to paste it with python.
I can't use PastePose for character because i have no character yet, i tried to use PasteObjectPose but my pose is
FBPose and i get AttributeError: 'FBPose' object has no attribute 'PasteObjectPose'.

All i need is just click "Paste" button, but i stuck with it for a day cause i need to do it with python.

 

P.S.: I'm new in motionbuidler scripting and after maya it seems quite hard.

Message 5 of 11

Message 6 of 11

Thank you for quick reply!

 

bindPose = FBObjectPose("Test")

fixed, it works fine now, so Doc is right.

 

I can create and work with FBObjectPose, but i have FBPose and trying to paste it. It seems to me that solusion is in 4th post of http://forums.autodesk.com/t5/motionbuilder-forum/trying-to-get-selected-pose-in-7-5ext2/td-p/407016...

 

So I'll try to use SetNodeMatrix() and SetNodeObject()

 

Message 7 of 11
ThomasGryphon
in reply to: kavalerov

With apologies for necro-posting, but I'm currently in a similar - if not exactly the same - situation:

We have access to a skeleton and an FBPose object living in Pose Controls... and the seemingly straightforward task of

from pyfbsdk import *
from pyfbsdk_additions import *
import os

app = FBApplication()
player = FBPlayerControl()
system = FBSystem()
scene = system.Scene
character = FBApplication().CurrentCharacter

selectedModels = FBModelList()
topModel = None
selectionState = True
sortBySelectOrder = True
FBGetSelectedModels(selectedModels, topModel, selectionState, sortBySelectOrder)

foundComponents = FBComponentList()
includeNamespace = True
modelsOnly = False
FBFindObjectsByName('*_Face_BasePose', foundComponents, includeNamespace, modelsOnly)

test_pose = None
for comp in foundComponents:
    print comp, type(comp)
    test_pose = comp
print test_pose
test_pose.__class__ = FBObjectPose  # tried this as FBPose not having 'paste' functions...
moreComponents = FBComponentList() includeNamespace = True modelsOnly = True FBFindObjectsByName('*_Eye', moreComponents, includeNamespace, modelsOnly) for comp in moreComponents: test_pose.PasteObjectPose(comp.Name, comp)
scene.Evaluate()

... unfortunately the calls to PasteObjectPose comes back complaining about:

Boost.Python.ArgumentError: Python argument types in
    FBObjectPose.PasteObjectPose(FBObjectPose, str, FBModelSkeleton)
did not match C++ signature:
    PasteObjectPose(class PYFBSDK::FBObjectPose_Wrapper {lvalue}, char const * __ptr64, class PYFBSDK::FBComponent_Wrapper {lvalue})

... which seems insane because everything derives from FBComponent, so then I checked good ol' TAO for the pyfbsdk_gen_doc to triple check that

def PasteObjectPose(self,pObjectName,pObject):
        """
        Paste the pose of all the properties of an object.

        pObjectName : Name of the object stored in the pose. 
        pObject : Object which will receive the values stored in the pose. 
        """
        pass

which also seems to imply that it really should *~just~* work as shown in the call

test_pose.PasteObjectPose(comp.Name, comp)

 

We're going forward with a brute force solution because time is not on our side, but if anyone can explain How FBPose or FBObjectPose pasting actually works, that would be great... and to clarify, No, we can't use/resort to CharacterPose

Message 8 of 11

 

Further apologies for the double post, but a more succinct example of what the problem is:

# Open a Scene, find either stored or merge external poses
# ...
poses = system.Scene.ObjectPoses
for pose in poses:
    # everything is returned as an FBPose...
    print pose.Name, pose

test_pose = poses[0]
test_pose.__class__ = FBObjectPose
# Technically cast to FBObjectPose... but probably not a great idea

selectedModels = FBModelList()
FBGetSelectedModels(selectedModels, None, True, True)

for s in selectedModels:
    try:
        test_pose.PasteObjectPose(s.Name, s)
    except Exception as e:
        print e
'''
fails with:
Python argument types in FBObjectPose.PasteObjectPose(FBObjectPose, str, FBModelSkeleton) did not match C++ signature: PasteObjectPose(class PYFBSDK::FBObjectPose_Wrapper {lvalue}, char const * __ptr64, class PYFBSDK::FBComponent_Wrapper {lvalue}) most likely angry due to the forced cast ''' # whereas making a pose 'manually'... another_pose = FBObjectPose("Another_Pose") #... for s in selectedModels: another_pose.PasteObjectPose(s.Name, s) # "works", but completely defeats any ability to operate with previously saved / imported poses

 

 

Message 9 of 11
Mocappy
in reply to: ThomasGryphon

Which version of MotionBuilder are you using? Your code worked fine in 2018 with a pose created with joints and models?

 

Below is a snippet that I think is doing what you are talking about - at least in MoBu 2018. I just added the merge options at the top in case that was breaking something, the rest is the same as your original post - I also add the Selection = True for "comp in foundComponents".

 

Only other thing I could think of is, "FBFindObjectsByName" is finding something that doesn't work with "PasteObjectPose".

 

Let me know if this helps,

 

Simon

 

from pyfbsdk import *

## Merge Pose File  
mergeOptions = FBFbxOptions( True )
# Discard all Elements. Discard all Animation
mergeOptions.SetAll(FBElementAction.kFBElementActionDiscard, False)
# Merge Poses
mergeOptions.Poses = FBElementAction.kFBElementActionMerge
# Discard All Settings
mergeOptions.BaseCameras = False
mergeOptions.CameraSwitcherSettings = False
mergeOptions.CurrentCameraSettings = False
mergeOptions.GlobalLightingSettings = False
mergeOptions.TransportSettings = False
# Turn off Open File window
mergeOptions.ShowOptionsDialog = False

# Path to Pose File
poseFile_path = r"C:\Desktop\poseTst.fbx"
# Merge Pose using file Merge options.
fileMergeSuccess = FBApplication().FileMerge( poseFile_path, False, mergeOptions)

if fileMergeSuccess:
    # Select Objects
    foundComponents = FBComponentList()
    includeNamespace = False
    modelsOnly = False
    FBFindObjectsByName('L_arm_*', foundComponents, includeNamespace, modelsOnly)
    # Select Components
    for comp in foundComponents:
        print comp, type(comp)
        # Select Objects
        comp.Selected = True
    
    poses = FBSystem().Scene.ObjectPoses
    for pose in poses:
        # everything is returned as an FBPose...
        print pose.Name, pose
        
    test_pose = poses[0]
    
    selectedModels = FBModelList()
    FBGetSelectedModels(selectedModels, None, True, True)
    
    for s in selectedModels:
        try:
            test_pose.PasteObjectPose(s.Name, s)
        except Exception as e:
            print e
Message 10 of 11
ThomasGryphon
in reply to: Mocappy

Failing to mention the MoBo versions (2016, 2017) tested against was my undoing...

After upgrading to 2019 everything worked as expected; thanks for taking a look @Mocappy

Message 11 of 11

A great !! I had not had time to look through the code, saw that this came up the other day again.

 

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

Post to forums  

Autodesk Design & Make Report