How do i manually UnSelect/Select the node SelectionManager

how do i manually select and un selection node programmatically.

Hello @raja.r,

To manually select a node, you can use selectNode(). To de-select, you can use clear(), remove() or toggle().

We publish a selection example as part of the quickstart section in the Communicator package. It demonstrates different selection options (including color customization). To view this particular example:

  1. Launch the server by double-clicking start_server.bat found in HOOPS_Communicator_2024.X.x\quick_start
  2. View the selection example by navigating to this URL:
    http://localhost:11180/selection.html?viewer=csr

Thanks,
Tino

1 Like

what if i want to remove selected node.

const selItem = window.Communicator.Selection.SelectionItem.create(nodeId);
    viewer.selectionManager.remove(selItem, true);
  

or

const selectedNodes = viewer.selectionManager.getResults();
    const nodesToBeDeleted = selectedNodes.filter(x=>x._nodeId === nodeId)
    const selItem = window.Communicator.Selection.SelectionItem.create(nodeId);
    if(nodesToBeDeleted.length){
      viewer.selectionManager.remove(nodesToBeDeleted, true);
  
    }

Hello @raja.r,

You’ll need to first add() the node to the selection set prior to calling remove():

const selItem = Communicator.Selection.SelectionItem.create(nodeId);
viewer.selectionManager.add(selItem); //add the node to the selection set
viewer.selectionManager.remove(selItem, true);

Thanks,
Tino

actually Selecting Node : Using mouse click directly on model element.
and Removing Node: Programmatically using below code

const selectedNodes = viewer.selectionManager.getResults();
    const nodesToBeDeleted = selectedNodes.filter(x=>x._nodeId === nodeId)
    if(nodesToBeDeleted.length){
      viewer.selectionManager.remove(nodesToBeDeleted, true);
  
    }

is it correct?

In your code snippet, you are targeting a specific node (variable nodeId) to be removed from the selection set. Your code will indeed work.

1 Like