Problem with Python autorig: 'tuple' object does not support item assignment

Problem with Python autorig: 'tuple' object does not support item assignment

Anonymous
Not applicable
1,801 Views
2 Replies
Message 1 of 3

Problem with Python autorig: 'tuple' object does not support item assignment

Anonymous
Not applicable

Hi, thanks for taking your time reading this 🙂

 

So I am fairly  new to programming in general and I received an assignment to create a simple FK autorig with Python. The problem that I ran into was when attempting to replicate the joints hierarchy but for the controllers. So I received this error: 'tuple' object does not support item assignment.

 

Here is the code:

 

import maya.cmds as cmds

number = '#'
Data = ()

Select = cmds.ls(sl=True, l=True)
Hier = cmds.listRelatives(Select[0], ad=True, f=True)
Hier.reverse()
Hier.insert(0, Select[0])

for i in Hier:
    if cmds.listRelatives(i, c=True): #If child = true, you get a controller
        Base = i.split('|')[-1]
        Zero = cmds.createNode('transform', n= number + 's_zero' + Base)
        Offset = cmds.createNode('transform', n= number + 's_zero' + Base)
        Ctrl = cmds.circle(n= number + 's_CTRL#' + Base)
        cmds.parent(Ctrl[0], Offset)
        cmds.parent(Offset, Zero)
        cmds.delete(cmds.parentConstraint(i, Zero))
        Data[i] = Ctrl[0]                        #<------------------------------------------It complains here
        Par = cmds.listRelatives(i, p=True, f=True)
        if Par:
            Par = Par[0]
            if Par in Data.keys():
                cmds.parent(Zero, Data[Par])

 

 

I hope that I posted this correctly x.x

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

viru.gupta8
Enthusiast
Enthusiast
Accepted solution

Hey buddy,

there is couple of issue:

first your create tuple  # Data=()

by looking to your code i advise you you should use dictionary   # Data={}

tuple don't have functionality like Data.keys() or Data[key]="something"

 

and one more thing in your code you create variable number="#" and creating name using it like

number+"name"

maya won't create names that start with number

you output will be "name" only.

 

i think these thing will fix your code.

Message 3 of 3

Anonymous
Not applicable

Yes, it works great! 🙂

 

And thanks for the naming point out, explains a different problem that I had.

0 Likes