Good day, everyone!
I have a hand-drawn straight line:
long _verticalHydraLineShapeId = _page.DrawLine(_verticalXStart, _verticalYStart, _verticalXEnd, _verticalYEnd); _lineShape = _page.Shapes.GetShape(_verticalHydraLineShapeId);
Then I place a connection point in the middle of the line.
Connection _connectionOnBreakout = new Connection(); _connectionOnBreakout.X.Ufe.F = "Width*0.5"; _connectionOnBreakout.Y.Ufe.F = "Height*0"; int _connectionPointOnHydraId = _lineShape.Connections.Add(_connectionOnBreakout);
In the created Visio document I see the correct line shape and the connection point in the middle. The connection point has been created with ID=0. When I place one more point on line it comes with ID=1. So everything seems to be correct.
Then I want to connect the created point to another point on another shape.
long _currentConnectorId = _diagram.AddShape(1, 1, "Dynamic connector", _page.ID);
_page.ConnectShapesViaConnectorIndex(_verticalHydraLineShapeId, _connectionPointOnHydraId, _sideBShapeId, _sideBConnectPointId, _currentConnectorId);
The neighbouring (SideB) shape is a standard rectangle with default connection points on its sides. Two standard rectangles connect always perfectly. But this connect between a rectangle and a line does not succeed. The dynamic connector object is created and placed in the corner of the page without connection anything. Is there a standard way to connect to the line? Or connection points on 1D-shapes can never connect to anything?
Now I use a workaround. I place a minimal rectangle in the place on line where the connection point must be and connect to any of its built-in connection points (point with ID=1 is used in my example).
double _lineCenterX = _verticalXEnd;
double _lineCenterY = _verticalYEnd + (_verticalYStart - _verticalYEnd) / 2;
long _addedFakeRectId = _diagram.AddShape(_lineCenterX, _lineCenterY, 0, 0, "Rectangle", _page.ID);
_page.ConnectShapesViaConnectorIndex(_addedFakeRectId, 1, _sideBShapeId, _sideBConnectPointId, _currentConnectorId);
This solution works but it seems to be weird. It would be better to use a standard connection point on line.