title: Create UV Set with openmaya API 2.0
body: <p>Im writing a custom reader node for maya (in python with openmaya API 2.0) and I would like to send my uv sets to a regular maya mesh node.</p>
  
  <p>Im wondering what would be the best way to push the uv sets in a mesh node? I wasn't able to find what data I have to create and how to send them to the mesh node.</p>
  
  <p>My reader is a <code>OpenMaya.MPxNode</code> who push custom data to a <code>OpenMaya.MPxSurfaceShape</code>. The shape is linked by out mesh / in mesh plugs to a regular maya mesh. I attempt to fill the uvSet plug of this shape using <code>compute</code> but without success. I expect the UVSets to be sent to the mesh. </p>
  
  <p>The following code sample is a limited test where my only goal is to create a new UVSet and attach it to the mesh. </p>
  
  <p>Any ideas or documentation which could help?
  I tried several things but I <strong>always</strong> get the error below.</p>
  
  <p><strong>The error:</strong></p>
  
  <pre><code>// Error: (kFailure): Object does not exist
  # Traceback (most recent call last):
  #   File "/path/to/maya/plug-ins/test_create_uv_set.py", line 60, in compute
  #     mesh.createUVSet("toto")
  # RuntimeError: (kFailure): Object does not exist // 
  </code></pre>
  
  <p><strong>The running code:</strong></p>
  
  <pre><code>"""
  usage
  
  import maya.cmds as cmds
  import pymel.core as pm
  
  cmds.loadPlugin("/path/to/maya/plug-ins/test_create_uv_set.py")
  
  transform_node = pm.polySphere(n='transform1', ch=1, o=1, r=4)[0]
  mesh1_node = transform_node.getShape()
  pm.setAttr(mesh1_node + ".visibility", False)
  uv_set_mod_node = pm.createNode("uvSetModifier", name="uvsetmodifier1")
  mesh2_node = pm.createNode("mesh", name="mesh2", parent=transform_node)
  pm.hyperShade(assign="initialShadingGroup")
  
  pm.Attribute.connect(mesh1_node.attr("outMesh"), uv_set_mod_node.attr("inMesh"))
  pm.Attribute.connect(uv_set_mod_node.attr("outMesh"), mesh2_node.attr("inMesh"))
  """
  
  import sys
  import maya.api.OpenMaya as OpenMaya
  
  
  def maya_useNewAPI():
      pass
  
  
  class uvSetModifier(OpenMaya.MPxNode):
      typeName = "uvSetModifier"
      id = OpenMaya.MTypeId(0xCCCCC)
  
      inMesh = None
      outMesh = None
  
      @staticmethod
      def creator():
          return uvSetModifier()
  
      @staticmethod
      def initialize():
          typedAttr = OpenMaya.MFnTypedAttribute()
  
          uvSetModifier.inMesh = typedAttr.create("inMesh", "im", OpenMaya.MFnData.kMesh)
          typedAttr.writable = True
          OpenMaya.MPxNode.addAttribute(uvSetModifier.inMesh)
  
          uvSetModifier.outMesh = typedAttr.create("outMesh", "om", OpenMaya.MFnData.kMesh)
          typedAttr.writable = True
          OpenMaya.MPxNode.addAttribute(uvSetModifier.outMesh)
  
      def __init__(self):
          OpenMaya.MPxNode.__init__(self)
  
      def compute(self, plug, datablock):
          if plug == uvSetModifier.outMesh:
              inputData = datablock.inputValue(uvSetModifier.inMesh)
              outputData = datablock.outputValue(uvSetModifier.outMesh)
              outputData.setMObject(inputData.asMesh())
              mesh = OpenMaya.MFnMesh(inputData.asMesh())
              mesh.createUVSet("toto")
              datablock.setClean(plug)
  
  
  def initializePlugin(obj):
      plugin = OpenMaya.MFnPlugin(obj, "Autodesk", "3.0", "Any")
  
      try:
          plugin.registerNode(uvSetModifier.typeName, uvSetModifier.id, uvSetModifier.creator, uvSetModifier.initialize)
      except:
          sys.stderr.write("Failed to register node\n")
          raise
  
  
  def uninitializePlugin(obj):
      plugin = OpenMaya.MFnPlugin(obj)
  
      try:
          plugin.deregisterNode(uvSetModifier.id)
      except:
          sys.stderr.write("Failed to deregister node\n")
          pass
  </code></pre>
  
  <p><strong>UPDATE 1: THEODOX input</strong></p>
  
  <p>I added the following line (59)</p>
  
  <pre><code>if inputData.asMesh() is not None:
     print "test"
     mesh = OpenMaya.MFnMesh(inputData.asMesh())
     mesh.createUVSet("toto")
  </code></pre>
  
  <p><strong>results</strong>: I still get the same error message</p>