Share

MAXScript Function Basics

This tutorial covers exposing your MCG graphs to MAXScript as functions, and executing arbitrary MAXScript inside graphs. This technique uses the Output: MAXScript Function and Evaluate MAXScript Operators.

In this tutorial, we will create a simple MCG graph, but instead of using as a tool from the 3ds Max UI, we will execute it from MAXScript. This graph will take two SceneNode inputs, and make one the child of the other in the scene hierarchy.

  1. Open a new, empty MCG graph.

  2. Add two Tool Input: SceneNode operators, naming the first "Child" and the second "Parent".

    Note: A graph called by MAXScript requires tool inputs, not compound inputs.
  3. Connect these inputs to a SceneNode Set Parent operator, the "Child" SceneNode to the "childNode" input, and the "Parent" SceneNode to the "parentNode" input.

  4. Finally, connect the SceneNode Set Parent output to an Output: MAXScript Function operator, which defines the end of the graph. The graph should look like this:

  5. Save and evaluate the graph, giving it the name "MCG_SetParent". You can test it out by switching to the 3ds Max MAXScript Listener and running some MAXScript commands:

     s = sphere()
     b = box()
     MCG_SetParent s b
  6. You can confirm that the new sphere is the parent of the box in the Scene Explorer:

  7. Let's add some arbitrary MAXScript and execute it from within the graph. In this case, we will get the parent scene node name and print it to the listener, using the Evaluate MAXScript operator. Essentially, we will execute a single line script: print "nodename". Add a SceneNode Name operator, and wire it to the Parent Tool Input: SceneNode (the tool output will now be wired to two nodes). Add the output of the SceneNode Name to the second input of a Join Strings operator, and wiring the first input (stringA) to a Constant with a value of print "SceneNode Parent:.

  8. We need to close the quote. Wire the output of the first Join Strings to stringA of second Join Strings, and wire stringB to a Constant with the value ". Finally, wire the string output to the input of an Evaluate MAXScript operator. This part of the graph should look like this:

  9. An MCG graph cannot have an un-wired output, but we also do not need the ScriptValue output of the Evaluate MAXScript operator. We can "throw the value away" by using one of the Ignore operators. Add an Ignore First operator, and wire the ScriptValue output to the first input. Wire the SceneNode output of the SceneNode Set Parent operator to the second value, then the SceneNode output of the Ignore First operator to our final Output: MAXScript Function operator.

  10. Save and evaluate the graph, and then re-run it in the listener. You should now see the resulting print script executing:

     s=sphere()
     $Sphere:Sphere001 @ [0.000000,0.000000,0.000000]
     t=teapot()
     $Teapot:Teapot001 @ [0.000000,0.000000,0.000000]
     MCG_SetParent s t
     "SceneNode Parent: Sphere001"
     dotNetObject:Autodesk.Max.MaxPlus.INode

This tutorial has covered a trivial example that illustrates how to create graphs that can be executed from MAXScript, and how to execute MAXScript from within an MCG graph.

Was this information helpful?