My first Maya Node

We will create a Kurtis node in order to build a solid in Maya. (You must have Maya installed on your computer to follow this tutorial)

 

First, we create a simple node :

 

  •  Create an animation block in the vartree. A graph is automatically created.

  • Open the graph (ctrl + o)

  • Press the tab key and select "MayaNodeTemplate". The parameters are preset to easily integrate Python commands to Maya.
  • (If you import it as a referenced node, right click on it and choose "Unlink Reference" to modify it.).

Next, we build a graph in an animation department block in order to check the result of this node :

  • Import the Maya node "Init" to initialize the software in order to send commands.

  • Connect its output "next" to the input "previous" of the "MayaNodeTemplate" node .

  • Import the node "SaveMayaFile" to save the scene.

  • Connect the "next" output of the "MayaNodeTemplate" node to the input "previous" of the "SaveMayaFile" node.
  • Double-click on the "SaveMayaFile" node and set the "Save path" parameter of the "SaveMayaFile" node.

We will now write the script of our node:

 

  • Right-click on the "MayaNodeTemplate" and pick "Edit Node"

  • Go to the "General" tab and rename it "polyPlatonicSolid".

  • Go to the "Scripts" tab and add in its script the command: "polyPlatonicSolid()".

 

  • Execute the graph by right-clicking on the "SaveMayaFile" node and choose "Execute".
  • When the Execute is finished, right-click again on this node and choose "Maya" to open the saved scene to check the result.

The command "polyPlatonicSolid()" has different arguments. They allow to :

 

  • Choose its name.

  • Select the type of solid to create.

  • Define its radius.


Create these parameters in the node interface :

  • Create a new input plug to define the name of the solid.
    Rename it "name".

  • Create a new input plug to define the type of solid to create.
    Rename it "solidType".
    Change its type into "list".
    Set its default value as "[0]".

  • Create a last input plug to set the radius of the solid.
    Rename it "radius".
    Change its type into "float".
    Set its default value as "1.0".

  • Click on "Apply"

  • Next, integrate these plugs in the node script. Assign value to each command argument.
    cmds.polyPlatonicSolid(name=plugs.name, solidType=plugs.solidType[0], radius=plugs.radius)

These plugs need a user interface :

 

  • Navigate to the tab "Plug UI".

  • Create a new widget of type "Line Edit".

  • Connect it to the "name" plug.
  • Next, create a new widget of type "List".

  • Connect it to the plug "solidType". Label it as you like.

  • Add to its parameters the list of possible solid creation :
    Dodecahedron / Icosahedron / Octahedron / Tetrahedron

  • Then change the "Output mode" setting in "Indices".

  • Click on "OK"  to validate
  • Create a type "Slider" widget.

  • Connect it to the plug "radius".

  • Click on "OK" to validate
  • Double-click on the polyPlatonicSolid node and change the settings of the command from the node interface.

  • Execute the "SaveMayaFile" node and open the file in Maya to see the different results.

You can also experiment with multiple "polyPlatonicSolid" nodes with different  parameters for each polyPlatonicSolid node.