Connection point placed on drawn line does not connect to anything

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.

@Viktor1983
Please try the following code to set the x and y values of the connection point. Otherwise, you will need to refresh the shape to update the coordinates of the connection point.

        _connectionOnBreakout.X.Ufe.F = "Width*0.5";
        _connectionOnBreakout.X.Value = shape.XForm.Width.Value * 0.5;

        _connectionOnBreakout.Y.Ufe.F = "Height*0";
        _connectionOnBreakout.Y.Value = 0; 

Thanks.

Good day, Philip!

It is becoming more interesting after I add the shape refresh command.

    int _connectionPointOnHydraId = _lineShape.Connections.Add(_connectionOnBreakout);
    _lineShape.RefreshData();

It breaks with System.NullReferenceException.
When “_lineShape.RefreshData()” is placed before “_lineShape.Connections.Add” it does not break.
The _lineShape object seems to be alright in my debugger. It is definitely not null. The added connection seems to be in place.Line_Output_1.png (8.8 KB)
Line_Output_2.png (21.8 KB)

@Viktor1983
Thanks for the screenshots and details.
Could you please create a standalone console application with latest version of Aspose.Diagram for .NET, zip the project and post us, we will check it soon.
Thanks.

Philip,

OK. I reproduced the algorythm in the console application. The listing of the single .cs file should be enough.Aspose_Connect_Demo_23_6.zip (861 Bytes)

@Viktor1983
Thanks for providing us the sample code,
After an initial test, I reproduced the issue as you mentioned by using template file.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): {DIAGRAMNET-53165}

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

The issues you have found earlier (filed as DIAGRAMNET-53165) have been fixed in this update. This message was posted using Bugs notification tool by philip.zhou

Hi, Philip!

Now I see that RefreshData method does not trigger an exception. It is good. But the requested function is still unavailable. You may uncomment all RefreshData code and you will see that a connector has been created but it does not connect two points.

@Viktor1983
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): DIAGRAMNET-53181

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@Viktor1983
Could you please add the following line to your code segment and then give it a try again, it should work fine:

        Connection _connectionOnMiddle = new Connection();
        _connectionOnMiddle.IX = 0;   // Add this line
        _connectionOnMiddle.X.Ufe.F = "Width*0.5";
        _connectionOnMiddle.Y.Ufe.F = "Height*0";

Thanks.

Hello, Philip!

I apologize that I could not check the feature earlier. I was very busy. Yes, now it connects perfectly. Later I found another issue concerned with connection points but it is more suitable for “group-ungroup” section. So I will place it there. Thank you.

@Viktor1983
Thanks for following the suggested workaround and good know that your issue is sorted out now.
Please feel free to contact us in case you have further comments or questions.