Programatically create a GoLink between two GoGeneralNodes



In my application, we use GoGeneralNodes to display a customized network diagram. We retrieve the network information (Nodes count, topology, capabilities, UIDs etc) via a middleware app and have to programatically create Nodes in the GoView component on the UI for the user. Thus far, after extracting valuable information I’ve been able to programatically create the GoGeneralNode objects on UI but am unable to find a way to create a GoLink between them so that they appear connected via their ports on the UI. I’ve only known a “User manually drags the ports to create a link between two nodes” approach and am kind of stuck on how to achieve this programatically. Is there a way to generate links that connect between ports of these nodes programatically? Thanks!


The basics…

  GoLink link = new GoLink ();   // (or GoLabledLink)
  link.FromPort = a;
  link.ToPort = b;

For a node (like GoBasicNode) that just has one port, a & b are just fromNode.Port and toNode.Port.

For GoSimpleNode, it would be fromNode.OutPort and toNode.InPort.

But GoGeneralNode has left and right port arrays. So it has GetLeftPort(int i) for input ports and GetRightPort(int i) for output ports.

so… “a” would be fromNode.GetLeftPort(0) and “b” would be toNode.GetLeftPort(0) (for example).


That solved it for me. Also, as an alternative, if someone needs it, there’s a goView.CreateLink() method available that links whichever ports of whichever nodes you like (they must be in the document). Beware of FromNode and ToNode properties since goView’s perspective might differ from what you conceptually perceive.

As always, you’re of great help, Jake, Thanks again!