title: Maya MPxNode multiple outputs
body: <p>I'm trying to create an <code>MPxNode</code> with multiple outputs, but I can only get one to work properly. The other output doesn't set properly after connecting the node and during undos.</p>
  
  <p>Is it possible to set both outputs at the same time in <code>compute</code> like how I'm trying to? It does work if I change the first line in compute to <code>if plug != self.output1 and plug != self.output2</code>, but that means it would calculate twice which is a waste of memory. And you could imagine how bad this would be if there were even more outputs.</p>
  
  <p>I managed to minimize the code to this simple example. I'm scripting it in Python on Maya 2018:</p>
  
  <pre><code>import maya.OpenMayaMPx as OpenMayaMPx
  import maya.OpenMaya as OpenMaya
  
  
  class MyAwesomeNode(OpenMayaMPx.MPxNode):
  
      # Define node properties.
      kname = "myAwesomeNode"
      kplugin_id = OpenMaya.MTypeId(0x90000005)
  
      # Define node attributes.
      in_val = OpenMaya.MObject()
      output1 = OpenMaya.MObject()
      output2 = OpenMaya.MObject()
  
      def __init__(self):
          OpenMayaMPx.MPxNode.__init__(self)
  
      def compute(self, plug, data):
          # Only operate on output1 attribute.
          if plug != self.output1:
              return OpenMaya.kUnknownParameter
  
          # Get input value.
          val = data.inputValue(MyAwesomeNode.in_val).asFloat()
  
          # Set output 2.
          # This fails when setting up the node and during undos.
          out_plug_2 = data.outputValue(self.output2)
          if val &gt; 0:
              out_plug_2.setFloat(1)
          else:
              out_plug_2.setFloat(0)
          out_plug_2.setClean()
  
          # Set output 1.
          # This works as expected.
          out_plug_1 = data.outputValue(self.output1)
          out_plug_1.setFloat(val)
          out_plug_1.setClean()
  
          data.setClean(plug)
  
          return True
  
  
  def creator():
      return OpenMayaMPx.asMPxPtr(MyAwesomeNode())
  
  
  def initialize():
      nattr = OpenMaya.MFnNumericAttribute()
  
      MyAwesomeNode.output2 = nattr.create("output2", "output2", OpenMaya.MFnNumericData.kFloat)
      nattr.setWritable(False)
      nattr.setStorable(False)
      MyAwesomeNode.addAttribute(MyAwesomeNode.output2)
  
      MyAwesomeNode.output1 = nattr.create("output1", "output1", OpenMaya.MFnNumericData.kFloat)
      nattr.setWritable(False)
      nattr.setStorable(False)
      MyAwesomeNode.addAttribute(MyAwesomeNode.output1)
  
      MyAwesomeNode.in_val = nattr.create("input", "input", OpenMaya.MFnNumericData.kFloat, 1)
      nattr.setKeyable(True)
      MyAwesomeNode.addAttribute(MyAwesomeNode.in_val)
      MyAwesomeNode.attributeAffects(MyAwesomeNode.in_val, MyAwesomeNode.output2)
      MyAwesomeNode.attributeAffects(MyAwesomeNode.in_val, MyAwesomeNode.output1)
  
  
  def initializePlugin(obj):
      plugin = OpenMayaMPx.MFnPlugin(obj, "Me", "1.0", "Any")
      try:
          plugin.registerNode(MyAwesomeNode.kname, MyAwesomeNode.kplugin_id, creator, initialize)
      except:
          raise RuntimeError, "Failed to register node: '{}'".format(MyAwesomeNode.kname)
  
  
  def uninitializePlugin(obj):
      plugin = OpenMayaMPx.MFnPlugin(obj)
      try:
          plugin.deregisterNode(MyAwesomeNode.kplugin_id)
      except:
          raise RuntimeError, "Failed to register node: '{}'".format(MyAwesomeNode.kname)
  
  
  # Example usage of node
  if __name__ == "__main__":
      import maya.cmds as cmds
  
      cmds.createNode("transform", name="result")
      cmds.setAttr("result.displayLocalAxis", True)
  
      cmds.createNode("myAwesomeNode", name="myAwesomeNode")
      cmds.connectAttr("myAwesomeNode.output1", "result.translateX")
  
      # This output fails.
      cmds.polyCube(name="cube")
      cmds.setAttr("cube.translate", 0, 3, 0)
      cmds.connectAttr("myAwesomeNode.output2", "cube.scaleX")
      cmds.connectAttr("myAwesomeNode.output2", "cube.scaleY")
      cmds.connectAttr("myAwesomeNode.output2", "cube.scaleZ")
  </code></pre>