We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Connector position

Hello,
When I use logic like the following to add a connector...
...
long srcId = diagram.AddShape(2, 6, 1, 1, "SourceShape", 0);
long tgtId = diagram.AddShape(2, 2, 1, 1, "TargetShape", 0);
var s = new Shape();
long cnId = diagram.AddShape(s, "MyConnector", 0);
page.ConnectShapesViaConnector(srcId, ConnectionPointPlace.Bottom,
tgtId, ConnectionPointPlace.Top, cnId);
diagram.Save("MyResult.vsdx", SaveFileFormat.VSDX);

... the connector appears about 1" [inch] too low, until I manually move it (click to select, then press up-arrow). At that point, the Visio page jumps and the page size increases from 22" to 24.5", while the connector jumps up. Pressing down-arrow brings it to its proper position.

Is there some more proper way to use the API to attach connectors to shapes?

Also, I can only see options to connect to the center of the [Top, Bottom, Left, or Right] sides of a shape; can you show me an example of how multiple connectors could lead, for instance, from across the bottom of a shape?

Thank you.

Hi,


Thank you for contacting support. The Visio page is resizing due to the Auto Size button. It is available on the Design tab, in the Page Setup group. Using Aspose.Diagram API, you can set AutoFitPageToDrawingContent property of the class DiagramSaveOptions as follows:

[.NET, C#]
<span class=“rem” style=“color: rgb(0, 128, 0); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>// load a Visio diagram<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
Diagram diagram = <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>new<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> Diagram(“c:\temp\Input.vsd”);<br style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”><span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
<span class=“rem” style=“color: rgb(0, 128, 0); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>// use saving options<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
DiagramSaveOptions options = <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>new<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> DiagramSaveOptions(SaveFileFormat.VSDX);
<span class=“rem” style=“color: rgb(0, 128, 0); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>// set Auto fit page property<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>options.AutoFitPageToDrawingContent = <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>false<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>;<br style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”><span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
<span class=“rem” style=“color: rgb(0, 128, 0); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>// save Visio diagram<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
diagram.Save(“c:\temp\Output.vsdx”, options);<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>

Each Visio shape has the connecting points. Connectors could only be connected to these points. The connecting point on a shape could be the concurrent point for multiple connectors. Please refer to these help topics: Add and Connect Visio Shapes and Working with Connector Type Shape

Thank you for the fast response. I tried revising logic to add a connector:
...
long srcId = diagram.AddShape(2, 6, 1, 1, "SourceShape", 0);
long tgtId = diagram.AddShape(2, 2, 1, 1, "TargetShape", 0);
var s = new Shape();
long cnId = diagram.AddShape(s, "MyConnector", 0);
page.ConnectShapesViaConnector(srcId, ConnectionPointPlace.Bottom,
tgtId, ConnectionPointPlace.Top, cnId);

var options = new DiagramSaveOptions(SaveFileFormat.VSDX);
options.AutoFitPageToDrawingContent = false;
diagram.Save("MyResult.vsdx", options);

... but the connector still appears precisely 1.5" [inch] too low, just as before.

I noticed when I open the result file in Visio, that the AutoSize button is selected, despite the logic to set options.AutoFitPageToDrawingContent = false.

So I reset the button in Visio, then select the connector; it jumps to position when I use the arrow key to move it up, then down, and this time the page size did not change. In fact, the connector jumps to position when I move a connected shape as well.

So I suspect the page size issue is not really related to the initial position of the connectors, which is the main issue.

Can you offer any work-around or resolution?

Thank you.
Aspose support:
Each Visio shape has the connecting points. Connectors could only be connected to these points. The connecting point on a shape could be the concurrent point for multiple connectors.

My further query:
Visio supports attaching Connector endpoints with "glue" to any point along the edge of a Shape. Is there no way to accomplish this with the Aspose API?

Thank you.

Hi,
kit.net:
I noticed when I open the result file in Visio, that the AutoSize button is selected, despite the logic to set options.AutoFitPageToDrawingContent = false.

So I reset the button in Visio, then select the connector; it jumps to position when I use the arrow key to move it up, then down, and this time the page size did not change. In fact, the connector jumps to position when I move a connected shape as well.

So I suspect the page size issue is not really related to the initial position of the connectors, which is the main issue.
Please provide us your source Visio drawing, code and highlight the issue with the help of a screenshot. It will help us to replicate the same problem on our side. We shall then investigate and reply you appropriately. Your response is awaited.
kit.net:
Visio supports attaching Connector endpoints with "glue" to any point along the edge of a Shape. Is there no way to accomplish this with the Aspose API?
Please refer to this helping article: Working with Shapes Gluing
Thank you for referring me to the article "Working with Shapes Gluing".
The "Glue Visio Shapes Programming Sample" example, unfortunately, illustrates the geometry limitation with its use of a ConnectionPointPlace.Center enum:

page.GlueShapes(shape1_ID,
Aspose.Diagram.Manipulation.ConnectionPointPlace.Center, shape2_ID);

This example and the "Glue Shapes Inside Programming Sample" below both seem to demonstrate precise control over where the shapes are attached, but the comments such as "...location on the first connection index where to glue" do not show how a "ConnectionIndex" is created or calculated. Please explain.

Thank you for your patience.

Hi,


Thank you for the inquiry. You can further ungroup a shape, and then select connection point to find out its index using Microsoft Visio application. However, if you are not able to glue shapes by index, then please share your source Visio drawing in this forum thread. We shall investigate and rely you appropriately.

Thank you for your response.


Should I understand, then, that Aspose requires assemblies of shapes to support attaching connector lines to specific locations?

I’m new to this, so thank you for your patience. If you have further documentation to guide me, please advise.

Thanks.

Hi,

Did you mean the stencil file of shapes? If so, then yes, because we shall investigate and see if it is already supported or not. It may possible that we also log an enhancement to achieve the said requirement. We recommend our clients share the complete details (including source Visio, stencil file if any, and code) of a use case so that we could replicate it on our side. It will help us investigate and reply to you appropriately.

I just learned that the stencils I am using in Visio are composed (by someone else) of shapes that provide the multiple glue points around the edge, as found with right-click > Show ShapeSheet.


[I’m sorry I could not share the files with you, as the process for sharing/publishing files is extensive.]

Is it possible to add to the Page API a way to ConnectShapesViaConnector using Connection Point index values for parameters instead of the limited ConnectionPointPlace enum?

I have further confirmed that the problem of connector position initially 1.5" too low is resolved by using an updated version of Aspose.Diagram.dll v17.3.2.0.


Edit/update: It works for connecting from Bottom to Top of another shape, but not when connecting from Right to Left.

Hi,


Thank you for the confirmation. It is nice to hear from you that the problem has been resolved. Please let us know in case of any further assistance or questions.