Ops, hadn’t noticed the thread title plug.
This might be more extensive than you’d want, but it’s also handling the selection and it’s unrolled to be clear, you can make it more compact or more versatile (e.g. make getPolySphere generic by passing the type of node you want to look for instead of having kPolySphere hard baked in there).
A safe way to find Node types is to test what functionalities they have with hasFn().
Haven’t checked this, it’s a hapzarded conversion of some C++ stuff I had open elsewhere, but I’m confident enough it’ll run or be pretty close to, and it should give you an idea of what to do and what to look for in the API.
Run it with an object selected (the transform, not its shape, as I extend to the shape from the transform in there).
from maya import OpenMaya as OM
# get the polysphere node connected to the dag path
# if there is one, otherwise return false
def getPolySphere(dagPath):
itrDG = OM.MItDependencyGraph(dagPath.node(),
OM.MItDependencyGraph.kUpstream,
OM.MItDependencyGraph.kPlugLevel)
itrDG.reset()
while not itrDG.isDone():
currentItem = itrDG.currentItem()
if currentItem.hasFn(OM.MFn.kPolySphere):
return currentItem
itrDG.next()
return False
# get the first shape under the first object in selection
def getFirstShapeInSel():
sel = OM.MSelectionList()
OM.MGlobal.getActiveSelectionList(sel)
dagPath = OM.MDagPath();
sel.getDagPath(0, dagPath)
dagPath.extendToShape()
return dagPath
dagPath = getFirstShapeInSel()
polySphere = getPolySphere(dagPath)
if polySphere:
# functionalities attached to a dependency node
# can be invoked from this
nodeFunctor = OM.MFnDependencyNode(polySphere)
attrib = nodeFunctor.attribute("radius")
# the plug is the actual functional port
# that gives you access to the attribute
plug = OM.MPlug( polySphere, attrib)
# get the plug's value as a double
print plug.asDouble()