# Absolute shape Grouped shape coordinates

Hi. How I can get correct coordinates of shape inside grouped shape? I found this topic Absolute shape coordinates, there are link: Calculate Pin Values and Setting Size of a Shape|Documentation

But this code example is legacy (property OffsetX or OffsetY don’t exist).

// Get pinx and piny
double pinx = m.OffsetX;
double piny = m.OffsetY;

For example we have two files. Different between them is that in second file shapes are grouped, so, has another coordinates.
First file, first shape has (non grouped):
PinX: 4.1732283464566926
PinY: 8.1692913385826742

Second file, first shape (grouped):
PinX: 1.1811023622047243
PinY: 2.8543307086614149

I need that PinX of grouped shape would be 4.1732283464566926 instead of 1.1811023622047243 and 8.1692913385826742 instead of 2.8543307086614149. Can you share working sample code how I can do this?
Test1.zip (39.6 KB)

@tvv91

We are looking into your inquiry and will get back to you shortly.

Hi. Any suggetions?

@tvv91

Would you please make sure to try using Aspose.Diagram for .NET 19.2 as the code is working with it. Furthermore, we have tested the scenario in our environment using latest version and were unable to retrieve desired PinX and PinY values. We used following code snippet for both Parent and Sub-Shapes:

``````// Load Visio diagram
Aspose.Diagram.Diagram diagram = new Aspose.Diagram.Diagram(dataDir + "second.vsd");
// Get a group shape by ID and page index is 0
Aspose.Diagram.Shape shape = diagram.Pages[0].Shapes.GetShape(6);
Aspose.Diagram.Shape subShape1 = shape.Shapes.GetShape(4);
Aspose.Diagram.Shape subShape2 = shape.Shapes.GetShape(5);
///
// Tried below code snippet with both subShape1 and subShape2
///
System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
// Apply the translation vector
m.Translate(-(float)shape.XForm.LocPinX.Value, -(float)shape.XForm.LocPinY.Value);
// Set the elements of that matrix to a rotation
m.Rotate((float)shape.XForm.Angle.Value);
// Apply the translation vector
m.Translate((float)shape.XForm.PinX.Value, (float)shape.XForm.PinY.Value);

// Get pinx and piny
double pinx = m.OffsetX;
double piny = m.OffsetY;
// Calculate the sub-shape pinx and piny
double resultx = shape.XForm.PinX.Value - shape.XForm.LocPinX.Value - pinx;
double resulty = shape.XForm.PinY.Value - shape.XForm.LocPinY.Value - piny;
//Console.WriteLine(string.Format("pinx={0}, piny={0}", pinx.ToString(), piny.ToString()));
``````

Nevertheless, we have logged an investigation ticket as DIAGRAMNET-51622 in our issue tracking system for further investigation of the scenario. We will surely let you know as soon as some definite updates are available regarding ticket resolution. Please spare us little time.

We are sorry for the inconvenience.

First problem was that in code example you are not type full namespace of Matrix object (System.Drawing.Drawing2D.Matrix), so i thought that is Aspose.CAD.Matrix.
Second, this code gets wrong coordinates (at least, in my case it’s wrong). My task - draw rectange with coordinates of shape. Rectangle coordinates I get by next code:

// convert constant from inches to pixels
private const float PX_PER_INCH = 0.0104166667F;

// pageHeight - height of page (~11,69…)
public Rectangle GetRectangle(Rectangle rectangle, float pageHeight)
{
// shape.PinX
rectangle.X = PageRectangle.X / PX_PER_INCH;
// shape.PinY
rectangle.Y = PageRectangle.Y / PX_PER_INCH;
// shape.Width
rectangle.Width = PageRectangle.Width / PX_PER_INCH;
// shape.Height
rectangle.Height = PageRectangle.Height / PX_PER_INCH;
rectangle.X = Math.Abs(rectangle.Width / 2 - rectangle.X);
rectangle.Y = pageHeight / PX_PER_INCH - rectangle.Y - rectangle.Height / 2;
return rectangle;
}

So, by this code I can calculate right shape coordinates, and draw rectangle on page image representation. But this code working only for ungrouped shapes. If using coordinates of shape inside grouped shape, then results wrong.

Suggest I have 2 documents, and want compare them, and if they some different, draw rectangle in that changed area. Test1.zip (42.2 KB)

Of course, I’m multiplicate Width and Height on 0.95F, so, blue rectangle some smaller, otherwise rectangle would be precisely drawing over shape black rectangle lines.

You can test this on your side. Just convert vsd page to image, and then draw rectangle with coordinates using code above.

@tvv91

Thanks for sharing more details.

We will definitely look into these details however, would you please try using following code snippet to get correct PinX and PinY values.

``````Aspose.Diagram.Shape shape = diagram.Pages[0](https://issue.nanjing.dynabic.com/issues/DIAGRAMNET-51622#fn0).Shapes.GetShape(6);
Aspose.Diagram.Shape subShape1 = shape.Shapes.GetShape(4);
Aspose.Diagram.Shape subShape2 = shape.Shapes.GetShape(5);
double pinx = subShape1.XForm.PinX.Value +subShape1.ParentShape.XForm.PinX.Value -subShape1.ParentShape.XForm.LocPinX.Value;
double piny = subShape1.XForm.PinY.Value + subShape1.ParentShape.XForm.PinY.Value - subShape1.ParentShape.XForm.LocPinY.Value;
``````

Please share your feedback with us in case you have other requirements as well. We will further proceed to assist you accordingly.

1 Like

Nice man. Working as I need. But again problem, what if one grouped shape in another grouped shape? For example we have grouped shape X, Y, Z.

X is common group shape, contains grouped shape Y and Z.

Grouped shapes Y and Z contains default rectangle shapes.

If I want calculate coordinates for example coordinates of some shape inside Y or Z, I must use coordinates of parent grouped shape X?

@tvv91