Graph manipulation

What is the project's "graph"?

The project's Graph represents all nodes of your project.

# Create an instance
from wysilab import InstantTerra
it = InstantTerra()

# Get the current graph
graph = it.project.graph

Retrieving the number of nodes in the graph

# Returns the numbers of nodes in the graph
number_of_nodes = graph.get_node_count()
print(number_of_nodes)

See get_node_count() in the documentation.

Retrieving all nodes in the graph

# Returns the list of nodes in the graph
list_of_nodes = graph.get_all_nodes()

The get_all_nodes() method lists the nodes of the graph.

Tip

More information about the nodes is found in the section Accessing node data.

Adding a node on the graph

# Add a node in the graph
newNode = graph.add_node(ApiNodeType.PERLIN_NOISE, (10, 10))

The add_node(ApiNodeType, tuple(int, int)) method creates a node on the graph at the specified location, and returns the new node.

Adding a node on the graph next to another one

# Add a node in the graph next to another one
newNode = graph.add_node_next_to(ApiNodeType.PERLIN_NOISE, NodeLocation.Right, previous_node)

The add_node_next_to(ApiNodeType, NodeLocation, Node) method creates a node on the graph next to a specified node, and returns the new node.

Removing a node from the graph

# Remove a node from the graph
graph.remove_node(nodeToRemove)

The remove_node(Node) method removes the node from the graph.


Copyright © 2022 · All Rights Reserved · Wysilab