Adding SBAtoms to SBGroupNode
-
Dear all,
I am trying to create a group of atoms that are distributed on several chains into a one SBNodeGroup.
In the following code I added every atom of my document into a SBNodeGroup, however it doesn't work as I cannot "Select group nodes" in the context menu and groupNodesSize is always zero. Am I missing something here?SAMSON::beginHolding("adding myModeGroup"); SBPointer<SBNodeGroup> nodeGroup = new SBNodeGroup(); nodeGroup->setName("myNodeGroup"); SBNodeIndexer allNodes; SAMSON::getActiveDocument()->getNodes(allNodes); nodeGroup->create(); SB_FOR(SBNode* node, allNodes) { if (node->getType() == SBNode::Atom) { nodeGroup->addChild(node); } } auto groupNodes = nodeGroup->getGroupNodes();; int allNodesSize = allNodes.size(); int groupNodesSize = groupNodes->size(); SAMSON::getActiveDocument()->addChild(nodeGroup()); SAMSON::endHolding();``` Thank you, Haichao -
Hi, @Haichao
You can actually do that using the SBNodeGroup constructor. It may look something like that:
// get an indexer with all the atoms // you can request specific nodes in the getNodes function itself using the Node Specification Language SBNodeIndexer nodeIndexer; SAMSON::getNodes(nodeIndexer, "node.type atom"); // or use getNodes function for any SBDataGraphNode you want with a predicate SAMSON::getActiveDocument()->getNodes(nodeIndexer, SBNode::IsType(SBNode::Atom)); // create a node group based on the nodeIndexer SBPointer<SBNodeGroup> nodeGroup = new SBNodeGroup("myNodeGroup", nodeIndexer); nodeGroup->create(); if (nodeGroup->isCreated()) { SAMSON::getActiveDocument()->addChild(nodeGroup()); } -
For some context: nodes in a group are not children of the group (a node can only have one parent), but only referenced by the group. As a result , the
addChildandremoveChildfunctions are not overloaded inSBNodeGroup, and they have the default behavior: they do nothing. The way to create groups is thus as @Dmitriy-Marin suggested :-).(This is similar to bonds, which only reference atoms, and are not parents of atoms.)
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login