problem with return function in python

problem with return function in python

saeeddameeres
Contributor Contributor
2,512 Views
5 Replies
Message 1 of 6

problem with return function in python

saeeddameeres
Contributor
Contributor

Hello, 

 

I'm trying to put the joints into sets by the naming convention but when I'm return the list, I'm getting nothing while if i print the list it will give me the joints. so the function is working but it's not returning. so please can i get some help with that and in the picture you can find the whole scene with the result.

 

Thanks 

 

that's my script:

 

 

import maya.cmds as cmds
def joints(): 
    token = 'joint'
    cornerToken = 'broadCorner'
    
    centerJoint = 'c_joint_broad_01'
    leftCornerJoint = 'l_joint_broadCorner_01'
    rightCornerJoint = 'r_joint_broadCorner_01'
    
    jointList = ['c_joint_01', 'l_joint_01', 'l_joint_02', 'l_joint_03', 'l_joint_04', 'l_joint_05', 'r_joint_01', 'r_joint_02', 'r_joint_03', 'r_joint_04', 'r_joint_05']
    
    lookUp = {'left': {}, 'right': {}, 'center': {}}
    
    for joints in jointList:
    
        if joints.startswith('c') and token in joints:
            lookUp['center'][joints] = [centerJoint]
    
        if joints.startswith('l') and token in joints:
            lookUp['left'][joints] = [centerJoint, leftCornerJoint]
    
        if joints.startswith('r') and token in joints:
            lookUp['right'][joints] = [centerJoint, rightCornerJoint]
    
        return lookUp
        
joints()

 

0 Likes
Accepted solutions (2)
2,513 Views
5 Replies
Replies (5)
Message 2 of 6

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

Your "return" statement is inside your For-loop (indented by 2 Tabs), so your function returns after the first iteration of the loop, which is also why you're not getting "nothing", if you look closely at the dict you returned in your screenshot, you'll see that the first joint has been sorted under 'center'.

 

Lower your return statements indentation level by 1 Tab and it will be fine.

 

I hope this helps!

Message 3 of 6

Hans_Redman
Advocate
Advocate
Accepted solution

For your joint list I think you can try to use the cmds.ls command. Instead of type them all.

jointList = cmds.ls( type='joint' )

https://download.autodesk.com/us/maya/2010help/CommandsPython/ls.html
Hope that helps.

0 Likes
Message 4 of 6

saeeddameeres
Contributor
Contributor

Thank you so much that solved it 

0 Likes
Message 5 of 6

saeeddameeres
Contributor
Contributor

it helps a lot, thanks for the advice 

Message 6 of 6

Hans_Redman
Advocate
Advocate
No worries.
0 Likes