The MASH API

The MASH API is a series of helper scripts that can be used to automate the setup and manipulation of MASH networks.

Basic Example 1.

Create a MASH network, add a couple of nodes, and print out some useful information.

import MASH.api as mapi
import maya.cmds as cmds

sphereToDistributeOn = cmds.polySphere(r=12)
cmds.polyCube()

# create a new MASH network
mashNetwork = mapi.Network()
mashNetwork.createNetwork(name="HelloWorld")
# print out the default node names
print mashNetwork.waiter
print mashNetwork.distribute
print mashNetwork.instancer
# add a Signal node
node = mashNetwork.addNode("MASH_Signal")
# set the signal node to have some scale noise
cmds.setAttr(node.name+".scaleX", 10)
# print out the name of the signal node
print node.name
# add a Falloff to the Signal node
falloff = node.addFalloff()
# move the falloff
falloffParent = cmds.listRelatives(falloff, p=True)[0]
cmds.setAttr(falloffParent+".translateX", 8)
# make it so the network distributes onto the surface of a mesh
mashNetwork.meshDistribute(sphereToDistributeOn[0])
# set the point count of the network
mashNetwork.setPointCount(1000)
# print all the nodes in the network
nodes = mashNetwork.getAllNodesInNetwork()
print "All nodes in network: "
print nodes
# find all the falloffs in the network
for node in nodes:
    mashNode = mapi.Node(node)
    falloffs = mashNode.getFalloffs()
    if falloffs:
        print node+" has the following falloffs: " + str(falloffs)

Basic Example 2.

Attach an existing network to Network class.

import MASH.api as mapi
mashNetwork = mapi.Network("MASH1")
print mashNetwork.waiter
print mashNetwork.distribute
print mashNetwork.instancer

See the MASH API Examples page for more examples.


The Network Class

class api.Network(name=None)

This class defines the base MASH network.

addChannelRandom(dynamicsNode)
Add a channel random node to either a MASH_Dynamics node or MASH_Constraint.
Returns a Node instance of the Channel Random node.
addCollider(colliderName)

Add a collider to the Bullet Solver this network is connected to.

addConstraint(dynamicsNode)
Add a constraint to a MASH_Dynamics node
Returns a Node instance of the Constraint node
addNode(nodeType)
Adds a node to the network.
If the node you’re creating is a curve node, then any curves defined in self.curves will be added automatically.
:param – nodeType: The node type as a string
:return – an instance of the Node class which can be used to further manipulate the network.
channelToList(channel, destination)

Copy an MArray to a list. This method is used mainly by MASH’s unit testing framework. :param – None :return – None

checkForNodeType(typeToCheckFor=None)
Returns true if a node of this type is present in the network.
:param – typeToCheckFor: The nodeType to check for.
:return – bool
createNetwork(name='MASH Network', distributionStyle=0, geometry='Default')
Creates a MASH network.
:param – name: The desired name of the new network.
:param – distributionStyle: The distribution style:
1 = Linear
2 = Radial
3 = Spherical
6 = Grid
7 = Initial State
8 = PFX
9 = Volume
:param – geometry: The geometry type:
‘Instancer’ will create a network using the Maya Particle Instancer.
‘Repro’ will use the MASH_Repro node to output a mesh.
To use mesh based distribition, first create the network, then use meshDistribute() and supply the required arguements.
Example:
import maya.cmds as cmds
import MASH.api as mapi
cmds.polyCube()
network = mani.Network()
network.createNetwork(geometry=’Instancer’)
createShellDynamics(meshes, freezeTransforms=True, name='MASH Shell Network')
Creates a MASH network with Shell Dynamics set up for every mesh in the meshes arguement list.
:param – name: The desired name of the new network.
:param – meshes: A list of meshes to add shell dynamics to.
Example:
selected = cmds.ls(sl=True)
mashNetwork = mapi.Network()
mashNetwork.createShellDynamics(selected, “DymamicsNetwork”)
getAllNodesInNetwork(name=None, foundNames=None, dest=True)
Returns the names of all the nodes in the MASH network
:return – list of names
getCurrentFrameData()
Gather the current frame’s data and write to lists:
self.position
self.rotation
self.scale
self.pid
self.time
This method is used mainly by MASH’s unit testing framework.
:param – None
:return – None
meshDistribute(mesh, mode=1)
Sets the MASH Network distribution method to mesh based.
:param – mesh: The name of the mesh on which to distribute.
:param – mode: The mesh distribution mode:
1 = Scatter
2 = Vertex
3 = Random Vertex
4 = Face
5 = Random Face
6 = Voxel
7 = Selection set
8 = Edge
9 = Random Edge
10 = UV Space
:return – nothing
rename(newPrefix)
Rename all the nodes in the MASH network.
You can name networks on creation (see above) thus this method should only be used when not creating networks via the API.
:param – newPrefix: The new prefix for the node names
:return – None.
setInitialState(dynamicsNode)
Sets the Initial State of a Dynamics network, only run this once
to set initial state a second time use
mc.setDynamicsInitialState(setState=True, name=dynamicsNodeName)
Returns a Node instance of the Initial State node
setPointCount(count)
Set the point count for the network.
:param – count: The new point count.
:return – nothing

The Node Class

class api.Node(nodeName)
This class defines a generic MASH node.
:string – name: The name of the MASH node
:list – falloffs: The falloffs on this node
addFalloff()
Add a Falloff node to the MASH node.
The name of the Falloff node will be returned.
addGroundPlane(groundTranform)

If the MASH node is a World node this function connects a ground plane to it. Otherwise it will return.

getFalloffs()

Returns the names of all the MASH Falloff objects as a list.