View Full Version : [Python API] Get connected shading node's name

07 July 2012, 11:28 PM
Hello guys,
i am learning the Python api and cause of that am trying to script a dependency graph node that
takes a shading nodes (file, ramp etc.) color attribute as an input and gives a color value at a certain UV position as an output.
Everything is set up so far, but now a problem occurs in the compute method:

When i want to get the name of the connected shadingnode and attribute (to pass it into the MRenderUtil.sampleShadingNetwork) the function loops like crazy!!
If i just have a transform nodes "translate" attribute connected it works just fine!
Does anybody have an idea how to fix that?

Here is the code of the compute method:
def compute(self, plug, data):

if(plug == uvSampleNode.outputCol or plug.parent() == uvSampleNode.outputCol):

#Get values from datablock
uCoord = data.inputValue(uvSampleNode.uCoord).asFloat()
vCoord = data.inputValue(uvSampleNode.vCoord).asFloat()

#Get Name of connected shading node
thisNode = uvSampleNode.thisMObject(self)
colPlug = OpenMaya.MPlug(thisNode, uvSampleNode.inputCol)


connectedShadingNodeArray = OpenMaya.MPlugArray()
colPlug.connectedTo(connectedShadingNodeArray, True, False)

if(connectedShadingNodeArray.length() > 0):

sys.stderr.write('Color plug not connected')

outputCol = data.inputValue(uvSampleNode.inputCol).asFloatVector()
outputColHandle = data.outputValue(uvSampleNode.outputCol)

return OpenMaya.MStatus.kUnknownParameter

return OpenMaya.MStatus.kSuccess

For example when pluggin in an empty groups translate i get "null1.translate" as a result on each update, when pluggin in a ramp i get "ramp1.outColorramp1.outColorramp1.outColorramp1.outColorramp1.outColorramp1.outColorramp1.outColor......."
until i disconnect with heavy delay..

CGTalk Moderation
07 July 2012, 11:28 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.