Simple Python code help to select finger effectors for only the current active character in a scene

Simple Python code help to select finger effectors for only the current active character in a scene

agnisen07
Enthusiast Enthusiast
837 Views
3 Replies
Message 1 of 4

Simple Python code help to select finger effectors for only the current active character in a scene

agnisen07
Enthusiast
Enthusiast

Hi all,


I am learning python and the first script I have written is a basic one that searches the scene for the Right and Left Hand finger effectors and puts them in separate Right and Left Groups for selection purposes. 

It works fine.

Now, I want to modify it so that when there are multiple characters in the scene, it will create groups only for the current active character.
As you can see from the code sample below, I have defined the current character and also received its namespace. I am stuck at the part where I go about making the code:
1. select only those RIGHT/LEFT Hand Finger effectors for the current character 
OR
2. search for the RIGHT/LEFT Hand Finger effectors for the current character and then select them


#Deselecting any previously selected objects in the scene
selectedModels = FBModelList()
FBGetSelectedModels(selectedModels)
for model in selectedModels:
    model.Selected = False

# Defining our Character as the currently selected one
lCharacter = FBApplication().CurrentCharacter
theNameSpace = lCharacter.LongName.split(":")
print theNameSpace

searchModelsOnly = True
searchInNamespace = False

#Searching for the Right Hand Finger Effectors in the scene and selecting them
rightfingersList = FBComponentList()
FBFindObjectsByName('RightHand*', rightfingersList, searchInNamespace, searchModelsOnly).theNameSpace
for comp in rightfingersList:
    comp.Selected = True
   
#Creating a Group 
group1 = FBGroup('RightFingers')

#Adding the selected Effectors to the group and then deselecting them
selectedModels = FBModelList()
FBGetSelectedModels(selectedModels)
for model in selectedModels:
    group1.Items.append(model)
    model.Selected = False


Any help or hint towards the right direction will be greatly appreciated! 
I searched the available resources online but I seem to be missing something or probably not understanding the function, so I am kind of stuck here.  

Thanks, peace!

0 Likes
Accepted solutions (1)
838 Views
3 Replies
Replies (3)
Message 2 of 4

victordebaie
Community Visitor
Community Visitor

posted with the wrong account, look for the answer below.

0 Likes
Message 3 of 4

vdebaie
Advocate
Advocate
Accepted solution

Hi, this bit of script should work for you:

 

 

 

from pyfbsdk import *

def ClearSelModel():
    modelList = FBModelList()
    FBGetSelectedModels (modelList, None, True)
    for model in modelList:
        model.Selected = False

##Selecte 'Right' or 'Left' Hand Effectors for the Current Character    
def SelectHandEffector(pHand):
    leftHand = ['LeftHandThumbEffector',
    'LeftHandIndexEffector',
    'LeftHandMiddleEffector',
    'LeftHandRingEffector',
    'LeftHandPinkyEffector'
    ]
    
    rightHand = ['RightHandThumbEffector',
    'RightHandIndexEffector',
    'RightHandMiddleEffector',
    'RightHandRingEffector',
    'RightHandPinkyEffector',
    ]
    
    ClearSelModel()
    
    for id in FBEffectorId.values.itervalues():
        if FBApplication().CurrentCharacter.GetEffectorModel(id) != None:
            if pHand == 'Left':
                for pFinger in leftHand:
                    if FBApplication().CurrentCharacter.GetEffectorModel(id).Name == pFinger:
                        FBApplication().CurrentCharacter.GetEffectorModel(id).Selected = True
                        
            if pHand == 'Right':
                for pFinger in rightHand:
                    if FBApplication().CurrentCharacter.GetEffectorModel(id).Name == pFinger:
                        FBApplication().CurrentCharacter.GetEffectorModel(id).Selected = True

##Select Right Hand Effectors
SelectHandEffector("Right")                        

##Select Left Hand Effectors
SelectHandEffector("Left")

 

 

I hope this helps.


I hope this helps.

 

0 Likes
Message 4 of 4

agnisen07
Enthusiast
Enthusiast
Hey thanks! This worked perfectly! And this also helped me with my learning progress of Python as well.
Thank you
0 Likes