# MTNodes Sample Project

#### Get the source code

```
git clone git@github.com:michaeltrainor/sample_mtnodes.git
```

#### Requirements:

Python 3.7.5+

#### Steps to run the sample:

from the root folder of the project run…

```
python -m mtnodes
```

#### Purpose:

The following code sample demonstrates a very basic graph evaluation. Documention is provided where necessary. I only documented the sample where I felt it would help guide you through the process. Any undocumented methods or classes are most certianly basic structures or instance properties.

#### Structure:

You will find an mtnodes package module (`__main__.py`

) that contains the sample code. I've copied the text below into a doc string for your convinience.

#### Summary:

Three nodes are added to a graph. The operator (an addition node) accepts two parameter nodes. In this case, simple constant values. As the output values of the constants are updated, the plugs for those nodes evalate downstream.

#### Details:

First two constant terms and an operator are registered to the graph. Next, the term ouputs are connected to the operator inputs. At this stage it may be helpful to pay attention the abstract_plug.py module, if you would like to follow the evaluation process. You would find that the output values of the terms are validated via an optional validation method that is implemented in the inherited node object. You can see an example of this in the math_constant_node.py.

Next, the term output values are set. And that's it. The graph evaluted each time a compute plug was notified of the change.

You will see a couple examples printed each time the terms changed.

```
# internal libraries
from mtnodes.abstract_graph import AbstractGraph
from mtnodes.math_add_node import MathAddNode
from mtnodes.math_constant_node import MathConstantNode
"""
The following code sample demonstrates a very basic graph evaluation
Summary:
Three nodes are added to a graph. The operator (an addition node) accepts two parameter nodes. In this case simple constant values. As the
output values of the constants are updated, the plugs for those nodes evalate downstream.
Details:
First two constant terms and an operator are registered to the graph. Next, the term ouputs are connected to the operator inputs. At this stage
it may be helpful to pay attention the abstract_plug.py module, if you would like to follow the evaluation process. You would find that the output values
of the terms are validated via an optional validation method that is implemented in the inherited node object. You can see an example of this in the
math_constant_node.py.
Next, the term output values are set. And that's it. The graph evaluted each time a compute plug was notified of the change.
You will see a couple examples printed each the terms changed.
"""
graph = AbstractGraph()
operator0 = graph.add_node(MathAddNode())
term0 = graph.add_node(MathConstantNode())
term1 = graph.add_node(MathConstantNode())
term0.output.connect(operator0.input0, as_input=True)
term1.output.connect(operator0.input1, as_input=True)
term0.output.value = 5.9
term1.output.value = 5
print("\nLet's add some nnumbers!")
print(f"{term0.output.value} + {term1.output.value} = {operator0.output.value}\n")
term0.output.value = 20
print("We changed a term...")
print(f"{term0.output.value} + {term1.output.value} = {operator0.output.value}\n")
term0.output.value = 1000 * 40
print("We changed the term again...")
print(f"{term0.output.value} + {term1.output.value} = {operator0.output.value}\n")
print("Thank you for your time. Please see the README.md\nin the root folder or follow the documetation above, in this module package\n")
```