0

I have a bit of an issue with parenting joints which are in one list.

spineJn = ['spine_IK_Jnt_A', 'spine_IK_Jnt_B', 'spine_IK_Jnt_C', 'spine_IK_Jnt_D', 'spine_IK_Jnt_E', 'spine_IK_Jnt_F', 'spine_IK_Jnt_G']

So, i need to make a joint chain out of these joints in this list. Key point is that I want to make it in reverse, meaning that the top Parent Joint is 'spine_IK_Jnt_A' and the end of the chain to be with 'spine_IK_Jnt_G'

I'm sorry for asking simple question, but I couldn't find anything online. Thank you in advance for any help.

azro
  • 53,056
  • 7
  • 34
  • 70
Val
  • 11
  • 4

1 Answers1

0

Because you want to refer to multiple items in a list at once, I believe it's the most straightforward to use indexes to manipulate your position within the list.

for index in range(len(spineJn) - 1):  # Iterate from 0 to 5 so we don't get an IndexError by going over 6 by doing + 1
    pm.parent(spineJn[index + 1], spineJn[index])

Alternatively, with some zip magic:

for cur, nxt in zip(spineJn, spineJn[1:]):  # spineJn[1:] offsets the list by one, and then we combine the two lists with zip
    pm.parent(nxt, cur)

Hope this helps!

meepzh
  • 707
  • 1
  • 7
  • 15