Edit Connector Bends
Add Bends to Connector
To add a bend to a connector, use the AddBend
method of the IConnector
object.
The bend is added at the end of the specified coordinates, starting from the associated source shape.
public void AddBend(ICommandContext c, ICommandParams p)
{
//Get the currently displayed diagram
IDiagram diagram = c.App.Workspace.CurrentEditor as IDiagram;
if (diagram == null)
{
//If no diagram is displayed, end the process
c.App.Output.WriteLine("sample", "Diagram is not displayed.");
return;
}
//Get the connector selected on the diagram
IConnector connector = diagram.GetSelectedShapes().OfType<IConnector>().FirstOrDefault();
if (connector == null)
{
//If no selection is made, end the process
c.App.Output.WriteLine("sample", "No connector is selected.");
return;
}
//Add a bend to the connector by specifying its coordinates
connector.AddBend(100, 150);
}
To add multiple bends, use the AddBends
method of the IConnector
object.
The bends are added last, starting from the source shape, in the order of the coordinates specified by System.Drawing.Point
.
public void AddBends(ICommandContext c, ICommandParams p)
{
//Get the currently displayed diagram
IDiagram diagram = c.App.Workspace.CurrentEditor as IDiagram;
//Get the connector selected on the diagram
IConnector connector = diagram.GetSelectedShapes().OfType<IConnector>().FirstOrDefault();
if (connector == null)
{
//If no connector is selected, terminate the process
c.App.Output.WriteLine("sample", "No connector selected.");
return;
}
//Add bends to a connector by specifying multiple coordinates
System.Drawing.Point position1 = new System.Drawing.Point(0, 50);
System.Drawing.Point position2 = new System.Drawing.Point(50, 50);
connector.AddBends(new []{ position1, position2 });
}
Get connector bends
To get the bends of a connector, use the GetBends
method of the IConnector
object.
You can get the bends in order starting from the connector's associated source shape.
public void GetBends(ICommandContext c, ICommandParams p)
{
//Get the currently displayed diagram
IDiagram diagram = c.App.Workspace.CurrentEditor as IDiagram;
//Get the connector selected on the diagram
IConnector connector = diagram.GetSelectedShapes().OfType<IConnector>().FirstOrDefault();
if (connector == null)
{
//If no connector is selected, terminate processing
c.App.Output.WriteLine("sample", "No connector selected.");
return;
}
//Get the coordinates of the bends that the connector has
int bendCount = 1;
IEnumerable<System.Drawing.Point> bendPositions = connector.GetBends();
foreach(System.Drawing.Point bendPosition in bendPositions)
{
c.App.Output.WriteLine("sample", $"Bend {bendCount} coordinates X:{bendPosition.X} Y:{bendPosition.Y}");
bendCount++;
}
}
Delete bends from connector
To delete bends from a connector, use the ClearBends
method of the IConnector
object.
All bends in the connector are deleted. You cannot delete specific bends.
public void ClearBends(ICommandContext c, ICommandParams p)
{
//Get the currently displayed diagram
IDiagram diagram = c.App.Workspace.CurrentEditor as IDiagram;
//Get the connector selected on the diagram
IConnector connector = diagram.GetSelectedShapes().OfType<IConnector>().FirstOrDefault();
if (connector == null)
{
//If no connector is selected, terminate the process
c.App.Output.WriteLine("sample", "No connector selected.");
return;
}
//Delete all bends from the connector
connector.ClearBends();
}