Finding nodes

Streams provide a number of ways of locating an existing node. These methods are summarized in the following table.

Table 1. Methods for locating an existing node
Method Return type Description
s.findAll(type, label) Collection Returns a list of all nodes with the specified type and label. Either the type or label can be None, in which case the other parameter is used.
s.findAll(filter, recursive) Collection Returns a collection of all nodes that are accepted by the specified filter. If the recursive flag is True, any SuperNodes within the specified stream are also searched.
s.findByID(id) Node Returns the node with the supplied ID or None if no such node exists. The search is limited to the current stream.
s.findByType(type, label) Node Returns the node with the supplied type, label, or both. Either the type or name can be None, in which case the other parameter is used. If multiple nodes result in a match, then an arbitrary one is chosen and returned. If no nodes result in a match, then the return value is None.
s.findDownstream(fromNodes) Collection Searches from the supplied list of nodes and returns the set of nodes downstream of the supplied nodes. The returned list includes the originally supplied nodes.
s.findUpstream(fromNodes) Collection Searches from the supplied list of nodes and returns the set of nodes upstream of the supplied nodes. The returned list includes the originally supplied nodes.
s.findProcessorForID(String id, boolean recursive) Node Returns the node with the supplied ID or None if no such node exists. If the recursive flag is true, then any composite nodes within this diagram are also searched.

As an example, if a stream contained a single Filter node that the script needed to access, the Filter node can be found by using the following script:

stream = modeler.script.stream()
node = stream.findByType("filter", None)
...

Alternatively, if the ID of the node (as shown on the Annotations tab of the node dialog box) is known, the ID can be used to find the node, for example:

stream = modeler.script.stream()
node = stream.findByID("id32FJT71G2")  # the filter node ID
...