maxon.GraphModelHelper

Description

Regroups functions to simplify the usage of the node API. Those functions help developers retrieving and manipulate information about a node system. Those functions mainly use internal function from the GraphModelInterface and do not offer more functionalities than what can be already done.

Inheritance diagram

Inheritance

Methods Signature

CreateInputPort(node, id, name)

Creates and returns a new InputPort.

CreateOutputPort(node, id, name)

Creates and returns a new OutputPort.

DeselectAll(graphModel, kind)

Deselect all True Nodes and ports based on the NODE_KIND passed as parameter.

DeselectConnection(srcPort, dstPort)

Deselects the connection between two ports. A connection hold a Wire object, itself holding 8 wires.

DeselectNode(node)

Deselects a node or a port.

FindNodesByAssetId(graphModel, assetId, exactId)

Find all true nodes that have the same AssetId as the passed argument. Only nodes have assetId.

FindNodesById(graphModel, nodeId, kind, …)

Find all true nodes that have the same AssetId as the passed argument. Only nodes have assetId.

FindNodesByName(graphModel, nodeName, kind, …)

Find all GraphNode (true nodes or ports) that have the same name as the passed argument.

GetAllPredecessors(node, filter[, callback])

Retrieves all nodes or ports connected to the passed port or node.

GetAllSuccessors(node, filter[, callback])

Retrieves all nodes or ports connected to the passed port or node.

GetDirectPredecessors(node, filter[, callback])

Retrieves the first level of nodes or ports connected to the passed port or node.

GetDirectSuccessors(node, filter[, callback])

Retrieves the first level of nodes or ports connected to the passed port or node.

GetSelectedConnections(graphModel[, callback])

Retrieves all the selected connections on the graph.

GetSelectedNodes(graphModel, kind[, callback])

Retrieves all selected ports and/or true node on the graph depending on the NODE_KIND passed as argument.

IsConnected(node, port)

Checks if this node or port is connected to another port.

IsConnectionSelected(srcPort, dstPort)

Checks if a connection between two port is selected. A connection hold a Wire object.

IsNodeSelected(node)

Returns if the node or the port is selected or not.

ListAllNodes(graphModel, matchingData[, …])

Retrieves all nodes having their stored data equals the ones in the passed DataDictionary.

MuteAllConnections(node, direction)

Mutes all incoming or outgoing connections of a node depending on the specified direction

MuteConnection(srcNode, dstPort)

Mutes the connection between a node or port and another port.

RemoveAllConnections(node)

Removes all the connection a true node have. The node should be a true node.

RemoveConnection(srcPort, dstPort)

Removes the connections between two port.

SelectConnection(srcPort, dstPort)

Selects the connection between two ports.

SelectNode(node)

Selects a node or a port.

UnmuteAllConnections(node, direction)

Unmutes all the connections in one direction.

UnmuteConnection(srcNode, dstPort)

Unmutes the connection between a node or port and another port.

Methods Definition

static GraphModelHelper.CreateInputPort(node, id, name)
Creates and returns a new InputPort.
The port will be identified by the passed id and will be renamed with the passed string.
This new port can only be created on the root or any group node.
Parameters
  • node (maxon.GraphNode) – The node where to create the input port.

  • id (Union[maxon.Id, str, maxon.String]) – The id of the port that need to be created.

  • name (Union[maxon.Id, str, maxon.String]) – The name of the port that need to be created.

Returns

The created port.

Return type

maxon.GraphNode

static GraphModelHelper.CreateOutputPort(node, id, name)
Creates and returns a new OutputPort.
The port will be identified by the passed id and will be renamed with the passed string.
This new port can only be created on the root or any group node.
Parameters
  • node (maxon.GraphNode) – The node where to create the output port.

  • id (Union[maxon.Id, str, maxon.String]) – The id of the port that need to be created.

  • name (Union[maxon.Id, str, maxon.String]) – The name of the port that need to be created.

Returns

The created port.

Return type

maxon.GraphNode

static GraphModelHelper.DeselectAll(graphModel, kind)

Deselect all True Nodes and ports based on the NODE_KIND passed as parameter.

Parameters
static GraphModelHelper.DeselectConnection(srcPort, dstPort)
Deselects the connection between two ports. A connection hold a Wire object, itself holding 8 wires.
There is at most one connection between two ports.
Parameters
static GraphModelHelper.DeselectNode(node)

Deselects a node or a port.

Parameters

node (maxon.GraphNode) – The node or the port that have to be Deselected.

static GraphModelHelper.FindNodesByAssetId(graphModel, assetId, exactId, callback=None)
Find all true nodes that have the same AssetId as the passed argument. Only nodes have assetId.
This function will return several nodes if they share the same assetId.
Parameters
  • graphModel (maxon.GraphModelRef) – The GraphModelRef to search for the nodes.

  • assetId (Union[str, maxon.String, maxon.Id]) – The AssetId of the true node or the port to look for. This has the form of a reversed domain string. e.g “net.maxon.asset.utility.color”

  • exactId (bool) – Set True if the exact id should be search. If this is set to False, check if the passed id is contained in the node assetID.

  • callback (Union[None, list, Callable[[maxon.GraphNode], bool]]) – This callback will receive all ports and/or True Node that have the same name.

Returns

If callback is None or a list then a list of maxon.GraphNode otherwise False if callback cancelled further evaluation, True otherwise.

Return type

Union[list[maxon.GraphNode], bool]

static GraphModelHelper.FindNodesById(graphModel, nodeId, kind, direction, exactId, callback=None)
Find all true nodes that have the same AssetId as the passed argument. Only nodes have assetId.
This function will return several nodes if they share the same assetId.
Parameters
  • graphModel (maxon.GraphModelRef) – The GraphModelRef to search for the nodes.

  • nodeId (Union[str, maxon.String, maxon.Id]) – The id of the true node or the port to look for.

  • kind (maxon.NODE_KIND) – Filter that will be applied to the kind of GraphNode we are looking for. By default, All type (true node/ports)

  • direction (maxon.PORT_DIR) – Filter the GraphNode by direction. Input or Output.

  • exactId (bool) – Set true if the exact id should be search. If this is set to false, check if the passed id is contained in the GraphNode’s id.

  • callback (Union[None, list, Callable[[maxon.GraphNode], bool]]) – This callback will receive all ports and/or True Node that have the same name.

Returns

If callback is None or a list then a list of maxon.GraphNode otherwise False if callback cancelled further evaluation, True otherwise.

Return type

Union[list[maxon.GraphNode], bool]

static GraphModelHelper.FindNodesByName(graphModel, nodeName, kind, direction, exactName, callback)
Find all GraphNode (true nodes or ports) that have the same name as the passed argument.
This function will return several nodes/port if they share the same name.

Warning

Name of true nodes or port can change depending on the language of Cinema4D.
Search based on name should be avoided as mush as possible, unless you are sure the name will not be different on any setup.
Parameters
  • graphModel (maxon.GraphModelRef) – The GraphModelRef to search for the nodes.

  • nodeName (Union[str, maxon.String]) – The name of the true node or the port to look for.

  • kind (maxon.NODE_KIND) – Filter that will be applied to the kind of GraphNode we are looking for. By default, All type (true node/ports)

  • direction (maxon.PORT_DIR) – Filter the GraphNode by direction. Input or Output.

  • exactName (bool) – Set true if the exact name should be search. If this is set to false, check if the passed name is contained in the GraphNode’s name.

  • callback (Union[None, list, Callable[[maxon.GraphNode], bool]]) – This callback will receive all ports and/or true node that have the same name.

Returns

If callback is None or a list then a list of maxon.GraphNode otherwise False if callback cancelled further evaluation, True otherwise.

Return type

Union[list[maxon.GraphNode], bool]

static GraphModelHelper.GetAllPredecessors(node, filter, callback=None)

Retrieves all nodes or ports connected to the passed port or node. This will only retrieve nodes or ports that are connected to the inputs.

Parameters
  • node (maxon.GraphNode) – The starting point to retrieve all the predecessor. A node or a port can be used. If a port is used, an input port must be used.

  • filter (maxon.NODE_KIND) – The NODE_KIND that will be included. The function search for all possible nodes or ports and will include them or not based on this filter.

  • callback (Union[None, list, Callable[[maxon.GraphNode], bool]]) –

    If a callable, this will be called with all the connected nodes.
    If a list is passed, connected nodes will be added to it.
    If a None is passed, a list containing connected nodes will be returned.

Returns

If callback is None or a list then a list of maxon.GraphNode otherwise False if callback cancelled further evaluation, True otherwise.

Return type

Union[list[maxon.GraphNode], bool]

static GraphModelHelper.GetAllSuccessors(node, filter, callback=None)

Retrieves all nodes or ports connected to the passed port or node. This will only retrieve nodes or ports that are connected to the outputs.

Parameters
  • node (maxon.GraphNode) – The starting point to retrieve all the successors. A node or a port can be used. If a port is used, an output port must be used.

  • filter (maxon.NODE_KIND) – The NODE_KIND that will be included. The function search for all possible nodes or ports and will include them or not based on this filter.

  • callback (Union[None, list, Callable[[maxon.GraphNode], bool]]) –

    If a callable, this will be called with all the connected nodes.
    If a list is passed, connected nodes will be added to it.
    If a None is passed, a list containing connected nodes will be returned.

Returns

If callback is None or a list then a list of maxon.GraphNode otherwise False if callback cancelled further evaluation, True otherwise.

Return type

Union[list[maxon.GraphNode], bool]

static GraphModelHelper.GetDirectPredecessors(node, filter, callback=None)

Retrieves the first level of nodes or ports connected to the passed port or node. This will only retrieve nodes or ports that are connected to the inputs.

Parameters
  • node (maxon.GraphNode) – The starting point to retrieve the direct predecessors. A node or a port can be used. If a port is used, an input port must be used.

  • filter (maxon.NODE_KIND) – The NODE_KIND that will be included. The function search for all possible nodes or ports and will include them or not based on this filter.

  • callback (Union[None, list, Callable[[maxon.GraphNode], bool]]) –

    If a callable, this will be called with all the connected nodes.
    If a list is passed, connected nodes will be added to it.
    If a None is passed, a list containing connected nodes will be returned.

Returns

If callback is None or a list then a list of maxon.GraphNode otherwise False if callback cancelled further evaluation, True otherwise.

Return type

Union[list[maxon.GraphNode], bool]

static GraphModelHelper.GetDirectSuccessors(node, filter, callback=None)

Retrieves the first level of nodes or ports connected to the passed port or node. This will only retrieve nodes or ports that are connected to the outputs.

Parameters
  • node (maxon.GraphNode) – The starting point to retrieve the direct successors. A node or a port can be used. If a port is used, an output port must be used.

  • filter (maxon.NODE_KIND) – The NODE_KIND that will be included. The function search for all possible nodes or ports and will include them or not based on this filter.

  • callback (Union[None, list, Callable[[maxon.GraphNode], bool]]) –

    If a callable, this will be called with all the connected nodes.
    If a list is passed, connected nodes will be added to it.
    If a None is passed, a list containing connected nodes will be returned.

Returns

If callback is None or a list then a list of maxon.GraphNode otherwise False if callback cancelled further evaluation, True otherwise.

Return type

Union[list[maxon.GraphNode], bool]

static GraphModelHelper.GetSelectedConnections(graphModel, callback=None)

Retrieves all the selected connections on the graph. A connection hold a Wire object. There is none or only one connection between two ports, and this connection is composed by multiple wires.

Parameters
Returns

If callback is None or a list then a list of maxon.GraphNode otherwise False if callback cancelled further evaluation, True otherwise.

Return type

Union[list[maxon.GraphNode], bool]

static GraphModelHelper.GetSelectedNodes(graphModel, kind, callback=None)

Retrieves all selected ports and/or true node on the graph depending on the NODE_KIND passed as argument.

Parameters
  • graphModel (maxon.GraphModelRef) – The GraphModelRef to retrieve the selected elements.

  • kind (maxon.NODE_KIND) – The GraphNode kind to check.

  • callback (Union[None, list, Callable[[maxon.GraphNode], bool]]) – The list or callable to pass the found nodes to.

Returns

If callback is None or a list then a list of maxon.GraphNode otherwise False if callback cancelled further evaluation, True otherwise.

Return type

Union[list[maxon.GraphNode], bool]

static GraphModelHelper.IsConnected(node, port)
Checks if this node or port is connected to another port.
If a true node is passed, every port on the node will be tested. If a port is passed, only the passed port will be tested.
Parameters
Returns

True if ports are connected, otherwise False.

Return type

bool

static GraphModelHelper.IsConnectionSelected(srcPort, dstPort)
Checks if a connection between two port is selected. A connection hold a Wire object.
There is at most one connection between two port, but this connection is composed by 8 wires.
If a GraphNode is passed instead a NodePath, the GraphNode will be converted to NodePath.
Parameters
Returns

True if the connection is selected, otherwise False.

Return type

bool

static GraphModelHelper.IsNodeSelected(node)

Returns if the node or the port is selected or not.

Parameters

node (maxon.GraphNode) – The Node or the Port to check.

Returns

True if the node or the port is selected, otherwise False.

Return type

bool

static GraphModelHelper.ListAllNodes(graphModel, matchingData, callback=None)
Retrieves all nodes having their stored data equals the ones in the passed DataDictionary.
The passed DataDictionary can have one or multiple data defined.
The function will compare all the value inside the DataDictionary, if they all match, the node will be returned.
# Retrieve all nodes with a defined name
nodeProperties = maxon.DataDictionary();
nodeProperties.Set(maxon.NODE.BASE.NAME, groupName)

for child in maxon.GraphModelHelper.ListAllNodes(nodeGraph, nodeProperties):
    print(f"node that have this name {child}")
Parameters
  • graphModel (maxon.GraphModelRef) – The GraphModelRef to list the node.

  • matchingData (maxon.DataDictionary) –

    The Dictionary filled with the data we want to compare the GraphNode with.
    All node founded that have the same data values than those passed within the Dictionary.

  • callback (Union[None, list, Callable[[maxon.GraphNode], bool]]) – This callback will receive all nodes founded that have the same data values than those passed within the Dictionary

Returns

If callback is None or a list then a list of maxon.GraphNode otherwise False if callback cancelled further evaluation, True otherwise.

Return type

Union[list[maxon.GraphNode], bool]

static GraphModelHelper.MuteAllConnections(node, direction)
Mutes all incoming or outgoing connections of a node depending on the specified direction
Parameters
  • node (maxon.GraphNode) – The true node to mute all the connections.

  • direction (maxon.PORT_DIR) – The direction where all connection will be muted.

static GraphModelHelper.MuteConnection(srcNode, dstPort)
Mutes the connection between a node or port and another port.
If a true node is passed, and the port is connected to one or several input port, all the connections will be muted between the port and the node.
For example, a constant port is connected to several input port of another node.
Parameters
static GraphModelHelper.RemoveAllConnections(node)
Removes all the connection a true node have. The node should be a true node.
To remove connection for a port, use GraphNodeFunctions.RemoveConnections()
Parameters

node (maxon.GraphNode) – The node to remove all the connections to.

static GraphModelHelper.RemoveConnection(srcPort, dstPort)

Removes the connections between two port.

Parameters
static GraphModelHelper.SelectConnection(srcPort, dstPort)

Selects the connection between two ports.

Parameters
static GraphModelHelper.SelectNode(node)

Selects a node or a port.

Parameters

node (maxon.GraphNode) – The node or the port that have to be selected.

static GraphModelHelper.UnmuteAllConnections(node, direction)

Unmutes all the connections in one direction.

Parameters
  • node (maxon.GraphNode) – The node to unmute the connection.

  • direction (maxon.PORT_DIR) – The direction where all connection will be Unmuted

static GraphModelHelper.UnmuteConnection(srcNode, dstPort)
Unmutes the connection between a node or port and another port.
If a true node is passed, depending of the port passed direction, every output or every input will be unmuted.
Parameters
  • srcNode (maxon.GraphNode) – The node to unmute the connection with.

  • dstPort (maxon.GraphNode) – The other port that the connection must be Unmuted.