Maya Python API Multiple Outputs Not Working

Maya Python API Multiple Outputs Not Working

Anonymous
Not applicable
2,066 Views
10 Replies
Message 1 of 11

Maya Python API Multiple Outputs Not Working

Anonymous
Not applicable

 

So I am very new to Python API.  I'm trying to create and advanced sine wave node.  The way I currently have it set up for the outputs is there is a main overall "outputs" compound attr (not an array), which branches off to several compound attrs ("output1", "output2", etc.), and each of those attributes has x,y,z.  The math all seems to be working, but it doesn't apply it to all of the outputs.  It just applies all of the values to the main "outputs" attr which sets it to "output1".  None of the other output attrs work, but I know the math is correct using print statements.  I also have the attributeAffects running so every input affects every output down to the x,y,z.  Why is the compute() not setting values for the other outputs?  Below is an abbreviated version of the code.  I tried using the setDependentsDirty method but it wasn't working.  Any help would be greatly appreciated.  

 

def compute(self, plug, dataBlock):
# sine math execution

if ( dpPlug == sineNode.outputs or (plug.isChild() and plug.parent() == sineNode.outputs )):

     # math blah blah

     # dataHandle.setFloat( ctrl1X )

     # dataHandle.setFloat( ctrl1Y )

     # dataHandle.setFloat( ctrl1Z )

     # dataHandle.setFloat( ctrl2X )

     # dataHandle.setFloat( ctrl2Y )

     # dataHandle.setFloat( ctrl2Z )

 

     dataBlock.setClean( plug )

0 Likes
Accepted solutions (1)
2,067 Views
10 Replies
Replies (10)
Message 2 of 11

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

Are you asking that xyz are not set during the compute? You need to get the handle of each child of the plug(x,y,z) and set them separately.

 

Yours,

Li

0 Likes
Message 3 of 11

Anonymous
Not applicable

Thank you for responding!  I do have the x,y,z handles, and I have the setFloat() for each dataHandle.  The problem is it seems to take all those outputs and combine them all into one and applies it output1, when I need them to also apply to output2, output3, etc.  Here is the code I have for the dataHandles:

 

if ( dpPlug == sineNode.outputs or (plug.isChild() and plug.parent() == sineNode.outputs )):

 

# I set the inputValue() here and apply asFloat() to them

 

ctrl1X = working math

ctrl1Y = working math

ctrl1Z = working math

etc.

 

outputsHandle = DataBlock.outputValue( sineNode.outputs )
output1Handle = outputsHandle.child( sineNode.output1 )
output1XHandle = output1Handle.child(sineNode.output1x)
output1YHandle = output1Handle.child(sineNode.output1y)
output1ZHandle = output1Handle.child(sineNode.output1z)

etc.

 

output1XHandle.setFloat( ctrl1X )
output1YHandle.setFloat( ctrl1Y )
output1ZHandle.setFloat( ctrl1Z )

etc.

 

dpDataBlock.setClean( plug )

 

I think it has something with the dirty propagation.  It seems to dirty just the main outputs attribute, but doesn't apply it to the individual output attrs and further into the x,y,z of each output.  I thought setDependentsDirty might do it, but that only activates when I manually change and input, and doesn't activate when I hit play on the timeline like I want it to.  Thank you and please help!

0 Likes
Message 4 of 11

cheng_xi_li
Autodesk Support
Autodesk Support
Hi,

Could you send me a sample for reproducing the issue? I could check if there is anything wrong with it.

Yours,
Li
0 Likes
Message 5 of 11

Anonymous
Not applicable

Also, ignore the "dpPlug" in the if statement, I had changed some of the naming to post this, so that code is working.

0 Likes
Message 6 of 11

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

I've looked at the setDependentsDirty. It is different from compute. It works like affectAttribute.

 

e.g. if plugBeingDirtied.partialName() == 'oft' :

....

 

Yours,

Li

0 Likes
Message 7 of 11

Anonymous
Not applicable

So I've made those changes, but the same problem still arises.  Only the first output gets all of the values, so only the first joint rotates.  Is there anything else you can see that's missing?

0 Likes
Message 8 of 11

cheng_xi_li
Autodesk Support
Autodesk Support
Hi,

I didn’t spot more errors right now. Would you mind upload your modified code with a sample scene?

P.S. I will be travelling this weekend, I will get back to you next week.

Yours,
Li
0 Likes
Message 9 of 11

Anonymous
Not applicable

I sent you the code in a message, attached is the scene I use to test it.  To create the node, use pm.createNode('dpSineNode') in the script editor.

0 Likes
Message 10 of 11

cheng_xi_li
Autodesk Support
Autodesk Support
Accepted solution

Hi,

 

I think you should get o1,o2,o3 with outputs.child and dirty outputs too. it should look like below:

 

 

			print "dirtying the other outputs"
			#thisNode = self.thisMObject()
			# o1 = thisNode.dpalSineNode( "output1")
			# o1 = MPlug(thisNode, dpalSineNode.output1)
			outs = fnThisNode.findPlug("outputs")
			o1 = outs.child(0)
			o1x = o1.child(0)
			affectedPlugs.append( o1x )
			o1y = o1.child(1)
			affectedPlugs.append( o1y )
			o1z = o1.child(2)
			affectedPlugs.append( o1z )
			affectedPlugs.append( o1 )
			# o2 = thisNode.dpalSineNode( "output2")
			o2 = outs.child(1)
			o2x = o2.child(0)
			affectedPlugs.append( o2x )
			o2y = o2.child(1)
			affectedPlugs.append( o2y )
			o2z = o2.child(2)
			affectedPlugs.append( o2z )
			affectedPlugs.append( o2 )
			# o3 = thisNode.dpalSineNode( "output3")
			o3 = outs.child(2)
			o3x = o3.child(0)
			affectedPlugs.append( o3x )
			o3y = o3.child(1)
			affectedPlugs.append( o3y )
			o3z = o3.child(2)
			affectedPlugs.append( o3z )
			affectedPlugs.append( o3 )
			affectedPlugs.append(outs)

Yours,

Li

 

 

0 Likes
Message 11 of 11

Anonymous
Not applicable

So I discovered the problem.  It was a typo issue on the dataHandle.set.  it read dataHandle1.set for all of them.  A little embarrassing but it works great now.  I did make the changes you suggested for the setDependentsDirty to function better, and thanks again for all of your help!

0 Likes