How to get the PolySphere Node from its Transform Node?

Hi guys!

I have created a polySphere in my scene and I would like to get access to its polySphere node.

I wrote the following pymel script.


import pymel.core as pm;

obj = pm.ls(selection=True);

print( obj );

The output is an array with 1 entry which is
[nt.Transform(u’pSphere1’)]

I would like to get access to the polySphere node so I can dynamically adjust the radius.
Is there anyway to get to the polySphere node from its transform node via listRelatives or some other command I don’t know? Thanks!

the result of creating the sphere with the polySphere command should return both the shape and the polySphere node.

cmds.polySphere()
// Result: [u’pSphere1’, u’polySphere1’] //

Hi rgkovach123!

Thanks however what if I am not creating the polySphere via code. What if one was created via an Artist and then they selected the object and ran my code? How would I be able to get the polySphere Node from the transform node?

for obj in pm.selected():
    print obj.history(type='polySphere')

Thanks capper! That is much closer to the solution I am looking for.
However I would still like to know if there is a way to find a relationship between an object’s transform node and its polySphere node. For example, given a transform, I can do listRelatives and gets its Mesh/Shape node. Why can’t I get the polySphere node in a similar way?

listRelatives returns related DAG nodes, and will only allow you to access parent/child/sibling/instance relationships. Since the polySphere node is not a DAG node, you have to get it using connections/history. Another way you can get to it is querying the connections a little more explicitly.

Assuming you know you are working with a transform of a shape:

shape = transform.getShape(noIntermediate=True)
polySphereNodes = shape.inputs(type='polySphere')
# This is more general and will return anything controlling the shape of the mesh
meshInputs = shape.inMesh.inputs()

print polySphereNodes
print meshInputs

# [nt.PolySphere(u'polySphere1')]
# [nt.PolySphere(u'polySphere1')]

Thank you so much Capper! This is what I was looking for!

By the way, if the polySphere node isn’t a DAG node, what kind of Node is it?
Also, how would I query whether or not a node is a DAG node in python? Thanks!

it’s a DG node.

a DAG node is your typical parent/child relationship. there is a hierarchy that prevents cycles. Directed Acyclic Graph.

A DG node is a dependency graph node. they have inputs and outputs, but no heirarachy, they can have many inputs and many outputs.

Outliner defaults to displaying only DAG nodes, you can turn it off, and then you can see all the DG nodes in your maya file. Things such as construction history and materials and files.