For Loop Problem

For Loop Problem

danielblaze
Contributor Contributor
1,249 Views
2 Replies
Message 1 of 3

For Loop Problem

danielblaze
Contributor
Contributor
I have a list of 15 joints split into chunks of 3. Each chunk should represent the joint hierarchy of a single finger.
 
[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11], [12, 13, 14]]
 
[0, 1, 2] = Thumb (thumb_base_JNT, thumb_01_JNT, thumb_02_JNT)
[3, 4, 5] = Index (index_base_JNT, index_01_JNT, index_02_JNT)
[6, 7, 8] = Middle (middle_base_JNT, middle_01_JNT, middle_02_JNT)
[9, 10, 11] = Ring (ring_base_JNT, ring_01_JNT, ring_02_JNT)
[12, 13, 14] = Pinky (pinky_base_JNT, pinky_01_JNT, pinky_02_JNT)
 
I want that the Thumb attributes loop through the thumb chunk [0, 1, 2] as at the moment it is looping through all of my joints. Same applies for the rest.
 
Sample Maya File attached. Select all objects in the set in order and run the code.
 
CODE:
 

import maya.cmds as cmds

sel = cmds.ls(os=1)
halfSel = len(sel)/2

# =============== CTRL Selection ================== #

srcCtrl = sel[0]

destCtrl = sel[halfSel]

# =============== CTRL Attributes ================= #

attrName = cmds.listAttr(srcCtrl, k = True)

# =============== Source JNTs and Destination JNTs ================= #

srcSel = []

for i in range(1,halfSel):
src=sel[i]
srcSel.append(src)

destSel = []

for i in range(halfSel + 1,len(sel)):
dest = sel[i]
destSel.append(dest)

# ===================== Default / Min / Max ======================= #

def mirVals(attrVal, attr):

# Loops in hand attributes (ex. thumb/pointer/etc) and goes through the Default / Min / Max values of both src and dest CTRLs for each joint in each finger)

chunk_size = 3

sel = range(15)

sel_chunk = []

for i in range(halfSel-1/chunk_size):
if (i+1)*chunk_size <= halfSel-1:
sel_chunk.append(sel[i*chunk_size:(i+1)*chunk_size])

for i, lst in enumerate(sel_chunk):

for x in range(3):

cmds.setAttr(srcCtrl + '.' + attr, attrVal[x])
cmds.setAttr(destCtrl + '.' + attr, attrVal[x])

print attr
print attrVal[x]

srcObjs = srcSel[i]
destObjs = destSel[i]

print lst

cmds.setAttr(destCtrl + '.' + attr, 0)
cmds.setAttr(srcCtrl + '.' + attr, 0)

# Getting default, Min & Max values

for ctrlAttr in attrName:
attrVal = []
attrVal.extend(cmds.attributeQuery(ctrlAttr, node = srcCtrl, listDefault = True))
attrVal.extend(cmds.attributeQuery(ctrlAttr, node = srcCtrl, range = True))

mirVals(attrVal, ctrlAttr)

0 Likes
Accepted solutions (1)
1,250 Views
2 Replies
Replies (2)
Message 2 of 3

jmreinhart
Advisor
Advisor

Could you maybe narrow down which part of your code isn't giving the desired result? At the moment it's hard to tell what you are trying to do.

0 Likes
Message 3 of 3

mcw0
Advisor
Advisor
Accepted solution

Might I suggest the following...

 

numOfJts = 15
jtsPerFinger = 3
fingers = ["thumb", "index", "middle", "ring", "pinky"]
for x in range(numOfJts/jtsPerFinger):
    print fingers[x]
    for y in range(jtsPerFinger):
        print ((jtsPerFinger*x)+(y%jtsPerFinger))

0 Likes