Skip to content
  • Recent
  • Tags
  • Popular
  • SAMSON Connect
  • Get SAMSON
Collapse
SAMSON Forum
  1. Home
  2. Develop
  3. Modeling
  4. Adding SBAtoms to SBGroupNode

Adding SBAtoms to SBGroupNode

Scheduled Pinned Locked Moved Solved Modeling
4 Posts 3 Posters 4.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H
    H
    Haichao
    wrote on last edited by
    #1

    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
    1 Reply Last reply
    0
    • DmitriyMarinD
      DmitriyMarinD
      DmitriyMarin
      wrote on last edited by DmitriyMarin
      #2

      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());
      }
      

      Dmitriy,
      The SAMSON Team, https://s-c.io

      1 Reply Last reply
      1
      • StephaneS
        StephaneS
        Stephane
        wrote on last edited by
        #3

        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 addChild and removeChild functions are not overloaded in SBNodeGroup, 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.)

        1 Reply Last reply
        1
        • H
          H
          Haichao
          wrote on last edited by
          #4

          Thanks, this solves my problem!

          1 Reply Last reply
          0

          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
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Recent
          • Tags
          • Popular
          • SAMSON Connect
          • Get SAMSON