Throughout the past 9 months I have been working on a Python script that makes setting up node networks in Maya fast and readable. It was suggested in Add more Math (trig) Nodes to submit the NodeCalculator as a separate suggestion.
What is the NodeCalculator?
Instead of writing a bunch of createNode, setAttr, connectAttr commands you can write a simple math formula and the node network is created for you. This makes prototyping and setup of node networks much faster, readable and fun. If needed; using the NodeCalculator-Tracer, the necessary, regular Maya cmds to get the node-network can be printed out.
It feels a bit like PyMel, with the big difference that the NodeCalculator is intended to create nodes & attributes on the fly, rather than simply giving an interface to interact with them.
The NodeCalculator was used in productions at DNEG and proved to be handy in many occasions.
This is the NodeCalculator code needed for an example node setup:
import node_calculator.core as noca
# Initiate Node-objects for all test-geos
a_geo = noca.Node("testA_geo")
b_geo = noca.Node("testB_geo")
c_geo = noca.Node("testC_geo")
# Average all directions of the A-translation
translate_a_average = noca.Op.average(a_geo.tx, a_geo.ty, a_geo.tz)
# Create a "floor collider" based on the height of B
b_height_condition = noca.Op.condition(b_geo.ty > 0, b_geo.ty, 0)
# Drive C-translation by different example-formula for each direction
c_geo.translate = [
b_geo.tx / 2 - 2,
b_height_condition * 2,
translate_a_average
]
in comparison: These are the necessary Maya cmds to get the equivalent node setup:
# Average all directions of the A-translation
var1 = cmds.createNode('plusMinusAverage', name='nc_AVERAGE_tx_ty_tz_plusMinusAverage')
cmds.setAttr(var1 + '.operation', 3)
cmds.connectAttr('testA_geo.tx', var1 + '.input3D[0].input3Dx', force=True)
cmds.connectAttr('testA_geo.ty', var1 + '.input3D[1].input3Dx', force=True)
cmds.connectAttr('testA_geo.tz', var1 + '.input3D[2].input3Dx', force=True)
# Create a "floor collider" based on the height of B
var2 = cmds.createNode('condition', name='nc_GT_ty_0_condition')
cmds.setAttr(var2 + '.operation', 2)
cmds.connectAttr('testB_geo.ty', var2 + '.firstTerm', force=True)
cmds.setAttr(var2 + '.secondTerm', 0)
cmds.connectAttr('testB_geo.ty', var2 + '.colorIfTrueR', force=True)
cmds.setAttr(var2 + '.colorIfFalseR', 0)
# Drive C-translation by different example-formula for each direction
var3 = cmds.createNode('multiplyDivide', name='nc_DIV_tx_2_multiplyDivide')
cmds.setAttr(var3 + '.operation', 2)
cmds.connectAttr('testB_geo.tx', var3 + '.input1X', force=True)
cmds.setAttr(var3 + '.input2X', 2)
var4 = cmds.createNode('plusMinusAverage', name='nc_SUB_outputX_2_plusMinusAverage')
cmds.setAttr(var4 + '.operation', 2)
cmds.connectAttr(var3 + '.outputX', var4 + '.input3D[0].input3Dx', force=True)
cmds.setAttr(var4 + '.input3D[1].input3Dx', 2)
var5 = cmds.createNode('multiplyDivide', name='nc_MUL_outColorR_2_multiplyDivide')
cmds.setAttr(var5 + '.operation', 1)
cmds.connectAttr(var2 + '.outColorR', var5 + '.input1X', force=True)
cmds.setAttr(var5 + '.input2X', 2)
cmds.connectAttr(var4 + '.output3Dx', 'testC_geo.translateX', force=True)
cmds.connectAttr(var5 + '.outputX', 'testC_geo.translateY', force=True)
cmds.connectAttr(var1 + '.output3Dx', 'testC_geo.translateZ', force=True)
I made a couple of introduction videos. The first video explains what the NodeCalculator is intended for:
The last video in the series is an example on how to use it:
The first version can be found on my GitHub page.
While the first version was used and tested in productions I have been working on the second version for a couple of months. Version 2 will be more versatile, stable and generally better thought through, since I reworked the entire core, based on what I learned from the first version.
If this is of interest I would be very happy to get in touch with the team of Autodesk Maya, to talk about how this could be implemented.