This class describes a group of nodes. In SAMSON, you can group selected nodes to perform various operations using them, e.g. to select the nodes in the group, intersect the current selection with the nodes in the group, etc.

A node group does not contain the nodes but only refers to them.

Node groups, as other nodes, can be added in a document.

Let’s for example create a group which contains references to all currently selected nodes.

Creating a node group#
# get the active document
activeDocument = SAMSON.getActiveDocument()

# get a node indexer of all currently selected nodes
selectedNodesIndexer = activeDocument.getSelectedNodes()

# construct a group based on the node indexer
group = SBNodeGroup("My selection", selectedNodesIndexer)

# turn the undo system on
SAMSON.beginHolding("Group selection")

# hold the group

# create the group (it node should be created before adding it to another node of the data graph)

# add the group to the active document

# turn the undo system off

You can get the node indexer of nodes in the group using the SBNodeGroup.getGroupNodes() function:

# print the number of nodes referenced by the group

# or get an indexer of nodes from the group
groupNodesIndexer = group.getGroupNodes()

See also

SAMSON SDK: SBDDataGraphNodeGroup

class samson.SBNodeGroup(*args, **kwargs)#

Bases: SBNode

This class describes a node group.

Overloaded function.

  1. __init__(self: samson.SBNodeGroup) -> None

Constructs an empty group

  1. __init__(self: samson.SBNodeGroup, name: str, nodeIndexer: samson.SBNodeIndexer) -> None

Constructs a group with name from nodes in nodeIndexer.

  • name (str) – A name of the group

  • nodeIndexer (samson.SBNodeIndexer) – An indexer of nodes that should be put into the group.


Create a group with all the atoms from the active document and add it to the active document in an undoable way.

>>> atomIndexer = SAMSON.getNodes('n.t a')
>>> group = SBNodeGroup('Atoms', atomIndexer)
>>> # add the group to the active document
>>> SAMSON.beginHolding('Add group') # make the operation undoable
>>> SAMSON.hold(group)
>>> group.create()
>>> SAMSON.getActiveDocument().addChild(group)
>>> SAMSON.endHolding()
getGroupNodes(self: samson.SBNodeGroup) samson.SBNodeIndexer#

Returns an indexer of nodes belonging to the group.


An indexer of nodes belonging to the group.

Return type:


getNextGroup(self: samson.SBNodeGroup) samson.SBNodeGroup#

Returns the next group

getPreviousGroup(self: samson.SBNodeGroup) samson.SBNodeGroup#

Returns the previous group

property size#

Returns the number of nodes belonging to the group