Programmatically select all nodes in a diagram

  1. How do I programmatically select all nodes in a diagram

  2. How do I programmatically scale selected nodes in a diagram?

  1. You can select all Parts that are selectable, including all Nodes, by: myDiagram.commandHandler.selectAll()

But if you only want to select Nodes (including Groups, but excluding simple Parts or Links):
myDiagram.clearSelection(); // don’t have anything else selected
myDiagram.selectCollection(myDiagram.nodes); // select all Nodes

  1. Perhaps:
    myDiagram.selection.each(function§ { if (p instanceof go.Node) p.scale = 1.1; });
    or if you assume all Nodes are already selected:
    myDiagram.nodes.each(function(n) { n.scale = 1.1; });
    Of course you will need to choose whether to set the GraphObject.scale of each Node, or whether to set the GraphObject.desiredSize of some element of each Node, in order to change their size.

Thanks for showing how to set the scale. what about the size? how do I set the size? Current, I’m able to iterate through a list of selected nodes and get the size via node.data.size. It will return me “32 32”

I tried this but it didn’t seem to work

        for (var it = e.diagram.selection.iterator; it.next(); ) {
            var node = it.value;  // part is now a Node or a Group or a Link or maybe a simple Part
            console.log(node.data.size);
            node.data.size = new go.Size(16, 16);

        }

If you want to modify model data objects, call Model.setDataProperty.
(I’m assuming there is a data binding. Don’t forget to wrap all of that code in a transaction.)

I tried doing this

for (var it = e.diagram.selection.iterator; it.next(); ) {
var node = it.value; // part is now a Node or a Group or a Link or maybe a simple Part
console.log(node.data.size);
console.log(node.desiredSize);

            node.desiredSize = new go.Size(16, 16);
        }  

It does change the size of my node, however it “chops” my node from its initial size of 32x32 down to 16x16 instead of resizing it.

How should I code it such that my node gets resized and scaled down instead of being trimmed down to 16x16?

Set scale to 0.5?
Or set desiredSize of the GraphObject that you care about, not the whole Node.

any idea?