Connect two shapes

Hello, I’m using the latest version of aspose.diagram for Node.js. I’m try to connect the two shapes using arrows, but I get an error. I used the next code:

const connector = new Shape();
const connectorId = page.getShapes().add(connector);

page.connectShapesViaConnector(
  shapeFrom.getID(),
  ConnectionPointPlace.BOTTOM,
  shapeTo.getID(),
  ConnectionPointPlace.TOP,
  connectorId,
);

In this case I get the following exception - com.aspose.diagram.Diagram.DiagramException: Shape 5 with ID 5 is not a Dynamic connector.
I tried to use drawLine to create a connector, but got strange results (drawLine.png).

const xFrom =
  shapeFrom.getXForm().getPinX().getValue() +
  shapeFrom.getXForm().getWidth().getValue() / 2;
const yFrom = shapeFrom.getXForm().getPinY().getValue();

const xTo =
  shapeTo.getXForm().getPinX().getValue() +
  shapeTo.getXForm().getWidth().getValue() / 2;
const yTo =
  shapeTo.getXForm().getPinY().getValue() +
  shapeTo.getXForm().getHeight().getValue();

const connectorId = page.drawLine(xFrom, yFrom, xTo, yTo);

I also created a connector using the Dynamic connector master from Basic Shapes.vss. In this case, everything works, but the connection points are in unexpected places (dynamic-connector.png).

Can I create a Dynamic connector without using the Stencil of Shapes?

drawLine.jpg (79.0 KB)
dynamic-connector.jpg (76.5 KB)

@YeCho
The Dynamic Connector is a 1D shape, If you want to create it yourself, you will need to fill in data such as BeginX, BeginY, and so on.
so it is preferable to add it from the “Basic Shapes” category for easier creation.
Thanks.

And what data other than BeginX, BeginY do I need to fill in? Thanks.

@YeCho
You need to fill in the values for BeginX and BeginY ,EndX and EndY according to the rules of Visio. Please refer to the following:
Cell N=‘BeginX’ V=‘4.75196850393701’ F='PAR(PNT(Sheet.1!Connections.X7,Sheet.1!Connections.Y7))
Cell N=‘BeginY’ V=‘6.409448818897638’ F='PAR(PNT(Sheet.1!Connections.X7,Sheet.1!Connections.Y7))
Cell N=‘EndX’ V=‘1.46259842519685’ F='PAR(PNT(Sheet.2!Connections.X4,Sheet.2!Connections.Y4))
Cell N=‘EndY’ V=‘3.499999918588782’ F='PAR(PNT(Sheet.2!Connections.X4,Sheet.2!Connections.Y4))

Thanks

1 Like