GraphNodes Manual

About

A maxon::GraphNode is a node of a maxon::GraphModelInterface graph. A maxon::NodePath is used to identify a node within that graph.

Access

A maxon::GraphNode is obtained from a graph model:

See GraphModelInterface Manual.

// This example shows how to obtain graph nodes from a graph model.
// get node space ID
const maxon::Id nodeSpaceID = GetActiveNodeSpaceId();
// check material
if (nodeMaterial->HasSpace(nodeSpaceID) == false)
return maxon::IllegalArgumentError(MAXON_SOURCE_LOCATION);
// get graph
const maxon::nodes::NodesGraphModelRef& graph = nodeMaterial->GetGraph(nodeSpaceID) iferr_return;
// get root node
const maxon::GraphNode rootNode = graph.GetRoot();
// get material node
maxon::NodePath materialNodePath;
nodeMaterial->GetMaterialNodePath(nodeSpaceID, materialNodePath) iferr_return;
const maxon::GraphNode materialNode = graph.GetNode(materialNodePath);
maxon::Id GetActiveNodeSpaceId()
Definition: graph.h:1937
Definition: apibaseid.h:253
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
#define iferr_return
Definition: resultbase.h:1465

GraphNode

The properties of a maxon::GraphNode are accessed with:

Graph node types returned by maxon::GraphNode::GetKind() are:

// This example checks if the given GraphNode is a real node and prints its ID.
// check if node
if (graphNode.GetKind() == maxon::NODE_KIND::NODE)
{
// get ID
const maxon::InternedId id = graphNode.GetId();
DiagnosticOutput("Node ID: @", id);
}
Definition: datatypelib.h:27
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
@ NODE
Indicates that the g-node is a true node.

The parent graph model and the path within that graph are obtained with:

// This example obtains the graph nodes model and path.
const maxon::GraphModelRef& graphModel = graphNode.GetGraph();
const maxon::NodePath& nodePath = graphNode.GetPath();
DiagnosticOutput("Path: @", nodePath);

The validity of a node is checked with:

Further utility functions are:

GraphNodeFunctions

maxon::GraphNode is based on maxon::GraphNodeFunctions.

The node can be removed from its model with:

The node hierarchy can be explored with:

// This example receives all child nodes of the given GraphNode.
// using a lambda function
lambda = [](const maxon::GraphNode& childNode) -> maxon::Result<maxon::Bool>
{
const maxon::InternedId id = childNode.GetId();
DiagnosticOutput("Node ID: @", id);
return true;
};
graphNode.GetChildren(lambda) iferr_return;
// or using a BaseArray
graphNode.GetChildren(childNodes) iferr_return;
for (const maxon::GraphNode& childNode : childNodes)
{
const maxon::InternedId id = childNode.GetId();
DiagnosticOutput("Node ID: @", id);
}
Definition: basearray.h:412
Definition: delegate.h:240
Definition: resultbase.h:766
#define iferr_scope
Definition: resultbase.h:1374
// This example searches in the given GraphModelRef for a node with the given nodeID and stores the node paths.
// array of node paths
// check all inner nodes of the root node
graph.GetRoot().GetInnerNodes(maxon::NODE_KIND::NODE, false,
[&paths, nodeID](const maxon::GraphNode& node) -> maxon::Result<Bool>
{
// get
const maxon::IdAndVersion id = node.GetValue<decltype(maxon::NODE::ATTRIBUTE::ASSETID)>().GetValueOrNull() iferr_return;
if (id.Get<0>() == nodeID)
{
// store node path
paths.Append(node.GetPath()) iferr_return;
}
return true;
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< T > Append(ARG &&x)
Definition: basearray.h:677
Definition: node.h:10

The port lists and ports of a node are obtained with:

Port directions are:

// This example obtains the input ports of the given GraphNode.
// get input port list
maxon::GraphNode inputPortList = node.GetInputs() iferr_return;
lambda = [](const maxon::GraphNode& port) -> maxon::Result<maxon::Bool>
{
// check if port
if (port.GetKind() == maxon::NODE_KIND::INPORT)
{
const maxon::InternedId id = port.GetId();
DiagnosticOutput("Port ID: @", id);
}
return true;
};
inputPortList.GetChildren(lambda) iferr_return;
// or using a BaseArray
inputPortList.GetChildren(ports) iferr_return;
for (const maxon::GraphNode& port : ports)
{
const maxon::InternedId id = port.GetId();
DiagnosticOutput("Port ID: @", id);
}
Result< Bool > GetChildren(const ValueReceiver< const GraphNode & > &callback, NODE_KIND mask=NODE_KIND::ALL_MASK) const
Definition: graph.h:1147
@ INPORT
Indicates that the g-node is an input port. An input port has an input port list or an input port as ...

Ports can be created with:

Ports of different nodes can be connected:

Connection can be muted or unmuted:

Connection can be checked with:

Connection can be removed with:

GraphNode selection can be checked with:

// This example gets the list of output connections for the given output port.
// get connections
port.GetConnections(maxon::PORT_DIR::OUTPUT, connections) iferr_return;
// check connections
for (const maxon::GraphConnection& connection : connections)
{
const maxon::GraphNode targetNode = connection.first;
const maxon::NodePath path = targetNode.GetPath();
DiagnosticOutput("Connected to : @", path);
}
const NodePath & GetPath() const
Definition: graph.h:1989
@ OUTPUT
Output direction, i.e., an output port or an outgoing connection.

A graph node can store multiple values:

Important values are:

  • maxon::nodes::PortType: The port type.
  • maxon::ConstantValue: The value stored in the port.
  • maxon::EffectiveName: The name of the node or port.

See maxon::NODE::BASE, graphattribs.h and portattributes.h.

// This example checks the input ports of the given node
// and prints the values of all ports of the type Float64.
// get input ports
maxon::GraphNode inputPortList = node.GetInputs() iferr_return;
inputPortList.GetChildren(ports) iferr_return;
// check each port
for (const maxon::GraphNode& port : ports)
{
DiagnosticOutput("Port: @", port.GetId());
// get data type
const maxon::DataType& type = port.GetValue<decltype(maxon::nodes::PortType)>().GetValueOrNull() iferr_return;
DiagnosticOutput("Data Type: @", type.GetId());
// check for float value
if (type.Is<maxon::Float64>())
{
// get data
const maxon::Float64 floatValue = port.GetConstantValue(maxon::Float64()) iferr_return;
DiagnosticOutput("Float value: @", floatValue);
}
}
Definition: datatypebase.h:772
double Float64
64 bit floating point value (double)
Definition: apibase.h:185
PyObject ** type
Definition: pycore_pyerrors.h:34
// This example gets all output ports of the given nodes and prints the port names.
// get output ports
const maxon::GraphNode outputPortList = node.GetOutputs() iferr_return;
outputPortList.GetChildren(outputPorts) iferr_return;
// print all port names
for (const maxon::GraphNode& currentport : outputPorts)
{
// get port name
const maxon::String portName = currentport.GetValue<decltype(maxon::EffectiveName)>().GetValueOrNull() iferr_return;
DiagnosticOutput("Port name: @", portName);
}
Definition: string.h:1235
// This example lists all attributes of the given node or port.
for (const auto& e : map)
{
const maxon::InternedId& key = e.GetKey();
const maxon::ConstDataPtr& data = e.GetValue();
DiagnosticOutput("Key: @, Data: @", key, data);
}
PyObject * key
Definition: abstract.h:289
Definition: datatypebase.h:1800
Definition: hashmap.h:1119
ValueIterator GetValues()
Definition: hashmap.h:2442
Py_ssize_t * e
Definition: longobject.h:89
DIRECT
Definition: materialexport.h:0

Further attribute settings are:

Warning and error messages are obtained with:

NodePath

A maxon::NodePath identifies a maxon::GraphNode within a node graph model. Only this path uniquely identifies a node.

A maxon::NodePath is obtain with:

If a node path is empty or not can be checked with:

Components and properties of the node path are:

A maxon::NodePath can be constructed with:

A maxon::NodePath can be converted:

Two paths can be compared with:

One can iterate over the components of a path with: