How can I get the coordinates of the center of a shape

Hi,

How can I get the coordinates of the center of a shape from a Visio file?
Here I attached a Visio file with a shape : Example.zip (9.5 KB)

Thank you

@roxi_t,
Please try the following code:

[C#]

string dataDir = @"C:\Diagram\test2202\";
// Call a Diagram class constructor to load the VSD diagram
Diagram diagram = new Diagram(dataDir + "Shape.vsdx");
// get page by name
Aspose.Diagram.Page page = diagram.Pages.GetPage("Page-1");
// get shape by ID
Aspose.Diagram.Shape shape = page.Shapes.GetShape(1);

Console.WriteLine(shape.XForm.PinX.Value);
Console.WriteLine(shape.XForm.PinY.Value);

Please refer to this help: Set Visio Shape’s XForm, Line and Fill Data

@imran.rafique,
Thank you for you help but I read from Visio documentation that those values are the coordinates of the center of rotation of a shape and not the coordinate of the shape center.
When you inserted a shape in Visio, by default the center of rotation of the shape is corresponding with the shape center ( see this file ByDefault.zip (9.5 KB) ) - so in this case the values of PinX and PinY are the coordinates of the center of rotation and the coordinates of the shape center as well.
When I change the center of rotation (that’s how I did in the file that you saw it first Example.zip) those values of PinX and PinY are changing as well, which means that in this case the center of rotation is not the same as the center of the shape. I need to know which is the coordinates of the center of the shape from the file Example.zip (9.5 KB)

@roxi_t,
If the target shape is not a group shape, then PinX and PinY are the absolute center coordinates in the Visio page. However, if the target shape is a Group shape, then the PinX and PinY are the absolute center coordinates in the group shape. We have documented a code example which calculates PinX and PinY coordinates of a subshape in relative to the page. Please refer to this help topic: Calculate PinX and PinY Values of the Sub Shape

It is because the shape changes its position with respect to the center of rotation. It is the default behavior of the Microsoft Visio application.

@imran.rafique - Thank you! What about the case where I have a group in another group. The inner group will be considered as a Sub Shape so should I calculate its PinX and PinY how I calculate them for a Sub Shapes?

@roxi_t,
You can apply a check in the code to verify whether the retrieved shape is a type of the Group or not, if it is the group shape, then you can iterates through the subshapes and calculate PinX and PinY values up to the multiple levels.

[C#]

if (shape.Type == TypeValue.Group)
foreach (Aspose.Diagram.Shape subshape in shape.Shapes)
{
    CalculateCoordinates(subshape);
}

@imran.rafique - I want to be sure that I’m understanding how it works - so if I have a shape(which is not a group - Example.zip (9.5 KB)
) and I change its center of rotation, PinX and PinY are still the coordinates of the center of the shape ? - I need the center coordinates of a shape because I have an algoritm that use this coordinates to get the shapes from a document in the order that are displayed in Visio, no as they are behind in page1.xml

@roxi_t,
You are right because the PINX and PINY are still the coordinates of the center of the shape in relation to the origin of its parent (Page). You can manually create a Visio drawing, and then move the shape by changing PINX and PINY values in the Microsoft Visio application and let us know if you come across any problem.

Ok, but I didn’t rotate or move the shape, I only changed the center of rotation of that shape. So I supposed that the shape should have the same center coordinates as it had before I changed center of rotation. Please see following files : Ex2.zip (34.9 KB) .

Thank you!

@roxi_t,
It is the default behavior of Microsoft Visio application and Aspose.Diagram mimics the behavior of the Microsoft Visio application. You can retrieve and store the latest PinX and PinY values after changing the center of rotation.

Ok. So from the second file (where I moved the center of rotation), I can’ t get the coordinates of the center of the shape onlythe values of PinX and PinY which are the only ones that indicates the position of the shape. Am I right?

What about LocPinX and LocPinY? Can you please tell me which is the difference between them and PinX and PinY?

@roxi_t,
You can get all values of the shape as available in the Shapesheet, including height, width, PinX, PinY, LocPinX and LocPinY. We will suggest you please review the Shapesheet.

Please refer to these help topics: PinX Cell (Shape Transform Section) and LocPinX Cell (Shape Transform Section)

Thanks a lot for you help !