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);

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);
}

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);
}
// 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;

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
{
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);
}

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 checkd with:

// This example gets the list of output connections for the given output port.
// get connections
// check connections
for (const maxon::GraphConnection& connection : connections)
{
const maxon::GraphNode targetNode = connection.first;
const maxon::NodePath path = targetNode.GetPath();
DiagnosticOutput("Connected to : @", path);
}

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
DiagnosticOutput("Float value: @", floatValue);
}
}
// 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);
}
// 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);
}

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:

DIRECT
DIRECT
Definition: materialexport.h:2
maxon::GraphNodeFunctions::GetValues
Result< void > GetValues(GraphAttributeInterface::FLAGS mask, GraphAttributeMap &map) const
Definition: graph.h:1618
maxon::NODE_KIND::NODE
@ NODE
Indicates that the g-node is a true node.
maxon::GraphNodeFunctions::GetChildren
Result< Bool > GetChildren(const ValueReceiver< const GraphNode & > &callback, NODE_KIND mask=NODE_KIND::ALL_MASK) const
Definition: graph.h:1258
maxon::DataType
Definition: datatypebase.h:735
maxon::Tuple< Id, Id >
maxon::String
Definition: string.h:1213
GetActiveNodeSpaceId
maxon::Id GetActiveNodeSpaceId()
maxon::Id
Definition: apibaseid.h:250
iferr_return
#define iferr_return
Definition: resultbase.h:1465
maxon::ConstDataPtr
Definition: datatypebase.h:1734
maxon::Float64
double Float64
64 bit floating point value (double)
Definition: apibase.h:181
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:66
maxon::BaseArray
Definition: basearray.h:366
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:167
maxon::GraphNodeFunctions::GetValue
Result< ConstDataPtr > GetValue(const InternedId &attr, const DataType &expectedType) const
Definition: graph.h:1654
maxon::GraphNode::GetKind
NODE_KIND GetKind() const
Definition: graph.h:2289
maxon::Result
Definition: apibase.h:316
maxon::GraphNodeFunctions::GetOutputs
Result< typename SFINAEHelper< GraphNode, BASE >::type > GetOutputs() const
Definition: graph.h:1302
maxon::BaseArray::Append
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< T > Append()
Definition: basearray.h:569
maxon::GraphNodeFunctions::GetConstantValue
Result< const T & > GetConstantValue(const T &def=maxon::NullValue< const T & >()) const
Definition: graph.h:1845
maxon::GraphNode::GetPath
const NodePath & GetPath() const
Definition: graph.h:2263
maxon::DataType::Is
Bool Is() const
Definition: datatype.h:1093
iferr_scope
#define iferr_scope
Definition: resultbase.h:1374
maxon::PORT_DIR::OUTPUT
@ OUTPUT
Output direction, i.e., an output port or an outgoing connection.
maxon::GraphNodeFunctions::GetConnections
Result< Bool > GetConnections(PORT_DIR dir, const ValueReceiver< const GraphConnection & > &conns, Wires mask=Wires::All(), GraphModelInterface::GET_CONNECTIONS_MODE mode=GraphModelInterface::GET_CONNECTIONS_MODE::CONNECTIONS) const
Definition: graph.h:1426
maxon::HashMap
Definition: hashmap.h:1114
maxon::InternedId
Definition: datatypelib.h:26
NodeMaterial::HasSpace
Bool HasSpace(const maxon::Id &spaceId) const
Definition: c4d_basematerial.h:403
NodeMaterial::GetMaterialNodePath
maxon::Result< void > GetMaterialNodePath(const maxon::Id &spaceId, maxon::NodePath &result) const
Definition: c4d_basematerial.h:411
NodeMaterial::GetGraph
maxon::Result< const maxon::nodes::NodesGraphModelRef & > GetGraph(const maxon::Id &spaceId) const
Definition: c4d_basematerial.h:475
maxon::GraphNodeFunctions::GetInputs
Result< typename SFINAEHelper< GraphNode, BASE >::type > GetInputs() const
Definition: graph.h:1291
maxon::Delegate
Definition: delegate.h:235
maxon::NODE_KIND::INPORT
@ INPORT
Indicates that the g-node is an input port. An input port has an input port list or an input port as ...
maxon::GraphNode::GetId
const InternedId & GetId() const
Definition: graph.h:2279
maxon::DataType::GetId
const Id & GetId() const
Definition: datatypebase.h:783
maxon::GraphNode
Definition: graph.h:2210