list of objects won't parent to group.

26 views
Skip to first unread message

jettam

unread,
Oct 16, 2017, 2:29:35 AM10/16/17
to Python Programming for Autodesk Maya
In this code I am trying to build a list of objects (bodyParts) as i go, and then parent that list to the master group (insectGroup) But I get this error.  Could someone tell me why my list wont parent to the group ?

# Error: Object [u'leftEye1', [u'leftProboscis'], [u'leftWingA'], [u'leftWingB'], [u'leftWingC']] is invalid
# Traceback (most recent call last):
#   File "<maya console>", line 1, in <module>
# TypeError: Object [u'leftEye1', [u'leftProboscis'], [u'leftWingA'], [u'leftWingB'], [u'leftWingC']] is invalid # 


bodyParts
=[]

#len(bodyParts)
# left eye
leftEye
= mc.polySphere(name='leftEye#',ch=0)[0]
bodyParts
.append(leftEye)

# left proboscis
LProboscis = mc.polyCylinder(name='leftProboscis',ch=0)
bodyParts
.append(LProboscis)

# left wing A
L_WingA
= mc.polySphere(n='leftWingA',ch=0)
bodyParts
.append(L_WingA)

# left wing B
L_WingB
= mc.polySphere(n='leftWingB',ch=0)
bodyParts
.append(L_WingB)


# left wing C
L_WingC
= mc.polySphere(n='leftWingC',ch=0)
bodyParts
.append(L_WingC)

# Put it all in a group
insectGroup
= mc.group(empty=True, name='Group_Insect_#')
mc
.setAttr((insectGroup)+ '.translate', 0, 1, 2, type="double3")

mc
.parent(bodyParts,insectGroup)



Justin Israel

unread,
Oct 16, 2017, 5:51:38 AM10/16/17
to python_in...@googlegroups.com
You are appending lists to lists (most the time) which is producing an undesirable result. In your first operation you actually take the first element from the list and append that. That is why you see only a string as the first element of your result 

leftEye = mc.polySphere(name='leftEye#',ch=0)[0]

All the others are left as a list. You can either continue taking just the first item from those inputs and appending them, or you can use ".extend()" on the list form:

LProboscis = mc.polyCylinder(name='leftProboscis',ch=0)[0]
bodyParts.append(LProboscis)

Or

LProboscis = mc.polyCylinder(name='leftProboscis',ch=0)
bodyParts.extend(LProboscis)



--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/f8c4e7b7-8acd-42c1-bbe0-1121c1eeb9c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jettam

unread,
Oct 16, 2017, 1:49:30 PM10/16/17
to Python Programming for Autodesk Maya
Thanks Justin. 

I have another related question. 
Is there a way I can grow the bodyParts list by doing this bodyParts.extend(sl=True) rather than bodyParts.extend(leftEye)  In other words, tell it the current object should be added to the list rather than having to explicitly give it a name ?
 
bodyParts=[]

#len(bodyParts)
# left eye
leftEye
= mc.polySphere(name='leftEye#',ch=0)

bodyParts
.extend(leftEye)


# left proboscis
LProboscis = mc.polyCylinder(name='leftProboscis',ch=0)

bodyParts
.extend(LProboscis)


# left wing A
L_WingA
= mc.polySphere(n='leftWingA',ch=0)

bodyParts
.extend(L_WingA)


# left wing B
L_WingB
= mc.polySphere(n='leftWingB',ch=0)

bodyParts
.extend(L_WingB)



# left wing C
L_WingC
= mc.polySphere(n='leftWingC',ch=0)

bodyParts
.extend(L_WingC)


# Put it all in a group
insectGroup
= mc.group(empty=True, name='Group_Insect_#')


mc
.parent(bodyParts,insectGroup)

Justin Israel

unread,
Oct 16, 2017, 2:21:49 PM10/16/17
to python_in...@googlegroups.com


On Tue, Oct 17, 2017, 6:49 AM jettam <justin...@gmail.com> wrote:
Thanks Justin. 

I have another related question. 
Is there a way I can grow the bodyParts list by doing this bodyParts.extend(sl=True) rather than bodyParts.extend(leftEye)  In other words, tell it the current object should be added to the list rather than having to explicitly give it a name ?

The extend() method is part of the python list type, not Maya's command module. So it has no knowledge of Maya and its selection system. You can however reduce your two lines into one by passing the results of one call to another, and avoiding the temp variable 

bodyParts.extend(mc.polySphere(name='leftEye#',ch=0))

If you don't like how that reads, you can use another form of extending a list. The += operator on a list is actually implemented to do the extend(), with the right side extending the left

bodyParts += mc.polySphere(name='leftEye#',ch=0)

 
bodyParts=[]

#len(bodyParts)
# left eye
leftEye
= mc.polySphere(name='leftEye#',ch=0)

bodyParts
.extend(leftEye)


# left proboscis
LProboscis = mc.polyCylinder(name='leftProboscis',ch=0)

bodyParts
.extend(LProboscis)


# left wing A
L_WingA
= mc.polySphere(n='leftWingA',ch=0)

bodyParts
.extend(L_WingA)


# left wing B
L_WingB
= mc.polySphere(n='leftWingB',ch=0)

bodyParts
.extend(L_WingB)



# left wing C
L_WingC
= mc.polySphere(n='leftWingC',ch=0)

bodyParts
.extend(L_WingC)


# Put it all in a group
insectGroup
= mc.group(empty=True, name='Group_Insect_#')


mc
.parent(bodyParts,insectGroup)

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages