SBNodeGroup#

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)

# make the operation undoable
with SAMSON.holding("Group selection"):
  # hold the group
  SAMSON.hold(group)
  # create the group (it node should be created before adding it to another node of the data graph)
  group.create()
  # add the group to the active document
  activeDocument.addChild(group)

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
print(group.size)

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

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.

Parameters:
  • name (str) – A name of the group

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

Examples

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
>>> with SAMSON.holding('Add group'): # make the operation undoable
...             SAMSON.hold(group)
...             group.create()
...             SAMSON.getActiveDocument().addChild(group)
True
getGroupNodes(self: samson.SBNodeGroup) samson.SBNodeIndexer#

Returns an indexer of nodes belonging to the group.

Returns:

An indexer of nodes belonging to the group.

Return type:

samson.SBNodeIndexer

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