How to add a selection to a list?

2,660 views
Skip to first unread message

Heather Rose

unread,
May 1, 2014, 6:11:14 AM5/1/14
to python_in...@googlegroups.com
Hi guys,

Say I had created 5 discs in my scene, disc0, disc1, disc2, disc3, disc4

I want to select the discs and add the to a list. I tried this out:

    pegA=[]
    pegA.append(cmds.select('disc*')
    print pegA

But it didn't work! It printed [None]

Any ideas on how else I could do this?

Thanks guys!

David Martinez

unread,
May 1, 2014, 6:16:55 AM5/1/14
to python_in...@googlegroups.com
Hi Heather,

It looks like you are selecting the objects instead of listing them.
Try this instead:

pegA=[]
pegA.append(cmds.ls('disc*'))
print pegA

Keep in mind though, that it will return both the transform node and the shape nodes.
Good news, is that you can specify the type using:

pegA=[]
pegA.append(cmds.ls('disc*',type='transform'))
print pegA

Hope it helps,




--
David Martinez - Technical Animator
 


--
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/e6adc889-906c-46ec-b900-aa9e757691e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
May 1, 2014, 6:28:37 AM5/1/14
to python_in...@googlegroups.com
cmds.ls() will return a list. If you're looking to add items to an existing list, there is a method called .extend:

>>> pegA.extend(cmds.ls(..))

Otherwise, you'll get a list within a list. Inception-style.



For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

David Martinez

unread,
May 1, 2014, 6:30:31 AM5/1/14
to python_in...@googlegroups.com
Oops! Good point!


--
David Martinez - Technical Animator
 


Heather Rose

unread,
May 1, 2014, 6:45:03 AM5/1/14
to python_in...@googlegroups.com
Hi David I just tried out your method, (with extend instead) and it works perfectly! thank you so much :)
Oops! Good point!
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
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_maya+unsub...@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com

--
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_maya+unsub...@googlegroups.com.

Heather Rose

unread,
May 1, 2014, 6:45:31 AM5/1/14
to python_in...@googlegroups.com
thank you!
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
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_maya+unsub...@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com

Reply all
Reply to author
Forward
0 new messages