How to switch the routing at runtime?

I use the below code to switch the routing after the diagram loaded, but no changes ???

var diagram = this.ActiveGraphItem();
diagram.startTransaction(“ChangeLinkType”);
switch (menuitem.text) {
case ‘Angle Lines’:
diagram.linkTemplate.routing = go.Link.AvoidsNodes;
//myDiagram.linkTemplate.isAngleView = true;
break;
case ‘Straight Lines’:
diagram.linkTemplate.routing = go.Link.Normal;
//myDiagram.linkTemplate.isAngleView = false;
break;
}
diagram.commitTransaction(“ChangeLinkType”);
diagram.layoutDiagram(true);

Your code should not be expected to modify the appearance of anything in your diagram because you are modifying a template, not an actual Link.

So if you really want to change the routing of all of the Links in your diagram, you need to iterate over each of the Links to set the Link.routing property:

function reroute() { myDiagram.startTransaction("toggle all routing"); myDiagram.links.each(function(l) { l.routing = (l.routing === go.Link.Normal) ? go.Link.AvoidsNodes : go.Link.Normal; }); myDiagram.commitTransaction("toggle all routing"); }

Thanks, it worked Smile

Hey, Default, my link template was using “AvoidNodes” and then I used the toggle button for “Normal”, In designer, links are changed to normal, however when draw a new link it uses “AvoidNodes”

How to fix this? Should I have to change the routing of link template? How to do that?

Do what you were doing before – in my “reroute” function set myDiagram.linkTemplate.routing to the desired value.

Hmmm, it sounds like toggling each Link’s Link.routing property isn’t what you want to do – you want to set them all to the same value. So you’ll want to change the code accordingly.

Works like a charm Smile