Reach Pull Effector Python Issues

Reach Pull Effector Python Issues

Anonymous
Not applicable
2,787 Views
8 Replies
Message 1 of 9

Reach Pull Effector Python Issues

Anonymous
Not applicable

hey guys..

 

so what I want or need to do is to set the reach/pull character settings via python.
I did search the internet and in here before posting and this is the thread/code I was testing:
can-the-ik-blend-t-and-r-reach-settings-be-set-on-control-rig 

 

I'm using Motionbuilder 2020 and the above code always returns none.
I made sure I'm selecting/accessing the proper character and everything.

 

character.GetEffectorModel(FBEffectorId.kFBRightWristEffectorId)


No matter what kind of ID I pass to GetEffectorModel I always get None returned.

My character does have a namespace but since I'm accessing the character properties

directly I wasn't expecting any issues here because of that.

This line of code does return something:

FBApplication().CurrentCharacter.PropertyList.Find('ReachActorRightWrist')

 

Just wanted to double check what I should be using or if I can use that approach instead?
If I should be using GetEffectorModel  why is it returning None for me?

 

cheers

0 Likes
Accepted solutions (4)
2,788 Views
8 Replies
Replies (8)
Message 2 of 9

vdebaie
Advocate
Advocate
Accepted solution

you can try this and see if it works for you:

 

def SetCurCharReachPull( pReach, pPull ):
    for property in FBApplication().CurrentCharacter.PropertyList:
        if "ReachActor" in property.Name:
            property.Data = pReach
    
    for property in FBApplication().CurrentCharacter.PropertyList:
        if "pull" in property.Name.lower():
            property.Data = pReach
Message 3 of 9

vdebaie
Advocate
Advocate
Accepted solution

you would use it like this for 100 pull and reach:

SetCurCharReachPull( 100, 100)
0 Likes
Message 4 of 9

Anonymous
Not applicable

Thanks,  I guess I could accept it but my questions was rather why the other way wasn't working! 😉
Because as I pointed out myself there's another approach!

0 Likes
Message 5 of 9

Anonymous
Not applicable

In the spirit of sharing the solution, this is what I'm using now (since the other approach doesn't work)

 

def getCharacterSettings(character):
    result = {
        'reach': {},
        'pull': {},
    }
    for propertyItem in character.PropertyList:
        if isinstance(propertyItem, FBPropertyAnimatableDouble) and propertyItem.Name.startswith('ReachActor'):
            result['reach'][propertyItem.Name] = float(propertyItem)
        if isinstance(propertyItem, FBPropertyAnimatableDouble) and propertyItem.Name.startswith('CtrlPull'):
            result['pull'][propertyItem.Name] = float(propertyItem)

    return result

def setCharacterSettings(character, settings):
    if 'reach' in settings:
        for name, value in settings.get('reach').iteritems():
            model = character.PropertyList.Find(name)
            if model:
                model.Data = float(value)
    if 'pull' in settings:
        for name, value in settings.get('pull').iteritems():
            model = character.PropertyList.Find(name)
            if model:
                model.Data = float(value)

settings = getCharacterSettings(FBApplication().CurrentCharacter)
setCharacterSettings(character, settings)

 

0 Likes
Message 6 of 9

Mocappy
Advocate
Advocate
Accepted solution

hi,

 

Does your character have a Control Rig?

currentCharacter = FBApplication().CurrentCharacter

Should get the current character you have in the scene - if you've just opened the file or you're unsure which is the "current character", just select it in Navigator>Characters. You could also find a specific character using it's name - something like this:

def GetCharacter(characterNamespace, characterName):
    characterFound = None
    for character in FBSystem().Scene.Characters:
        if character.LongName == characterNamespace + ":" + characterName:
            characterFound = character
            continue

    return characterFound

 Once you've got your character, you will need to check there's a Control Rig and create one if there isn't

if not currentCharacter.GetCurrentControlSet():
    currentCharacter.CreateControlRig(True)
    currentCharacter.InputType = FBCharacterInputType.kFBCharacterInputMarkerSet
    currentCharacter.ActiveInput = True

Then you should be able to find the right wrist effector:

rightWristEffector = currentCharacter.GetEffectorModel(FBEffectorId.kFBRightWristEffectorId)

- this is a snip from some code I'm using in 2018, which does work, although I'm setting different attributes.

 

Hope this helps,

Message 7 of 9

Anonymous
Not applicable

Thanks I will try this next week, sorry I'm super busy.
I'm using this code for the re-targeting process.

So I have two characterized characters and one is driving the other.
So I'm not really adding a ControlRig in my workflow but was still expecting this to work.

0 Likes
Message 8 of 9

Anonymous
Not applicable

Thanks a lot for both replies @vdebaie @Mocappy !

 

P.S. +THANK YOU that you are 2 of my main 7 motionbuilder python sources on the internet!

Message 9 of 9

Mocappy
Advocate
Advocate
Accepted solution

Ah, that would explain why you're code isn't working and you can't find the "FBEffectorId.kFBRightWristEffectorId". This is part of the Control rig an only exists when you create one.

 

Never done it this way and only done a quick search, but if you did want to set values in python, you would need to use Vic's solution, or hard code the separate values using something like this:

currentCharacter = FBApplication().CurrentCharacter
leftHandReachAtrr = currentCharacter.PropertyList.Find('Left Hand Reach T')
leftHandReachAtrr.Data = 100.0

 

If you're doing this for retargeting, another option would be to create a "Mapping File" that contains your source character driving your target character - no animation. Just in T-Pose. In this file you would set all your Pull and Reach settings to make sure the mapping is working. Then in python, you can open your mapping file, import the animation on your target character. Plot the animation to your source character. Delete your target character and Save. Rinse and repeat for all fbx files in folder. This also lets you reuse the code for any Source>Target character setup.

 

Hope this helps,