2

I'm in the process of creating a custom import plugin for maya. I already wrote some import code and created a custom MPxSurfaceShape class (I'm mainly interested in drawing the surface from within the viewport).

The shape gets crated by a MPxCommand which reads a file from the disk. Now I would like to add this object to my maya scene from within the plugin. But unfortunately I can't find a function that takes a MPxNode/MPxSurfaceShape and adds it to Maya so that it can be displayed.

In all examples I've seen the node is instantiated from within mel. But I want to link this instance a file. Which prevents me from just creating the node and then editing it.

A similar solution might be found in either the apiMeshShape example in the maya plugin folder or here: https://github.com/ADN-DevTech/Maya-Locator/ (also supports the loading of external data).

Pascal
  • 831
  • 2
  • 11
  • 24

1 Answers1

3

Here's something I hope will help.

 MDagModifier dagMod;
 MObject newNode = dagMod.MDGModifier::createNode("Node Name")
 dagMod.doIt()

or

 MDagModifier dagMod;
 MObject newNode = dagMod.MDGModifier::createNode(Node::id)
 dagMod.doIt()

From there you have an MObject you can make into other things.

 //Dag Node example.
 MFnDagNode new_MDagNode(newNode);

 //Dependency Node.
 MFnDependencyNode new_DependNode(newNode);

The MPxNode also has thisMObject() which will give you the current MObject in the MPxNode. http://download.autodesk.com/us/maya/2010help/API/class_m_px_node.html#9608c582da0945e792c3f9893661404d

Again I'm not sure I fully understand the question, but I hope this helps.

chribis
  • 277
  • 7
  • 26
  • Awesome! Thanks! I'll have a look at it. – Pascal May 29 '14 at 08:06
  • I think I should better start from scratch. I think I need to restructure the plugin: The `apiMeshShape` example looks very similar to the problem I'm trying to solve. – Pascal May 29 '14 at 10:06
  • Thanks! I also found the https://github.com/ADN-DevTech/Maya-Locator/ with the customLocator node which essentially does what I want. – Pascal May 29 '14 at 14:11
  • Accepting the solution, since my question is ambiguous and solutions can be found on the web. – Pascal May 29 '14 at 14:14