Linking and unlinking nodes

When you add a new node to a flow, you must connect it to a sequence of nodes before it can be used. Flows provide a number of methods for linking and unlinking nodes. These methods are summarized in the following table.

Table 1. Methods for linking and unlinking nodes
Method Return type Description
s.link(source, target) Not applicable Creates a new link between the source and the target nodes.
s.link(source, targets) Not applicable Creates new links between the source node and each target node in the supplied list.
s.linkBetween(inserted, source, target) Not applicable Connects a node between two other node instances (the source and target nodes) and sets the position of the inserted node to be between them. Any direct link between the source and target nodes is removed first.
s.linkPath(path) Not applicable Creates a new path between node instances. The first node is linked to the second, the second is linked to the third, and so on.
s.unlink(source, target) Not applicable Removes any direct link between the source and the target nodes.
s.unlink(source, targets) Not applicable Removes any direct links between the source node and each object in the targets list.
s.unlinkPath(path) Not applicable Removes any path that exists between node instances.
s.disconnect(node) Not applicable Removes any links between the supplied node and any other nodes in the specified flow.
s.isValidLink(source, target) boolean Returns True if it would be valid to create a link between the specified source and target nodes. This method checks that both objects belong to the specified flow, that the source node can supply a link and the target node can receive a link, and that creating such a link will not cause a circularity in the flow.

The example script that follows performs these five tasks:

  1. Creates a Data Asset node, a Filter node, and a Table output node.
  2. Connects the nodes together.
  3. Filters the field "Drug" from the resulting output.
  4. Runs the Table node.
stream = modeler.script.stream()
sourcenode = stream.findByID("idGXVBG5FBZH")
filternode = stream.createAt("filter", "Filter", 192, 64)
tablenode = stream.createAt("table", "Table", 288, 64)
stream.link(sourcenode, filternode)
stream.link(filternode, tablenode)
filternode.setKeyedPropertyValue("include", "Drug", False)
results = []
tablenode.run(results)