Search code examples
pythonpython-2.7mayapymel

How to access PyNode from a PyNode list?


I ran this example code with 2 polyCubes in scene.

import pymel.core as pymel

pymel.select('pCube1', 'blinn1')
print pymel.ls(sl = True)
print pymel.ls(sl = True)[0]

and this is my output

[nt.Transform(u'pCube1'), nt.Blinn(u'blinn1')]
pCube1

I know the elements inside this list are PyNodes, but printing them gives out a string type name of the node. Is there anyway to access the PyNode directly from this list?


Solution

  • Found the answer myself.

    So apparently the Script Editor returns a representation of PyNode when we print it. Like it's an overloaded str. It is still a PyNode but looks like a string only in Maya's Script Editor. To make it actually appear like a PyNode, we have to use repr() or enclose in back-ticks (`)

    Here is the link where I found the answer. : http://download.autodesk.com/us/maya/2011help/pymel/tutorial.html

    Formatting: Read Me First to Avoid Confusion section