Im trying to get the X Y coordinates of objects relative to the 0,0 top left of parent… it seems that the Adobe XD Panel always has the correct position that i want. i have used globalBounds ,localbounds, boundsinparent, topleftinparent, GlobalDrawBounds and the X Y never match with the one i see in the X Y position in the Adobe Panel… take a look at the screenshots to see what i mean. None of the mentioned properties have the x y coordinates of whats shown on the panel. Is there a formula to get that position? If so, could someone help point out how to get that same coordinates as you see there?
i noticed that if i ungroup the groupings i then get an accurate number in boundsinParent.
However, i still want to be able to use Groupings but still have the children in the group give me a x y coordinate relative to the artboard itself OR relative to the Group absolute top left 0,0 coordinates
any ideas or helps… this is a PSD file that i opened in XD… perhaps i need to do some cleaning up… any help would be fine
The X and Y coordinates that are displayed in the GUI of the XD properties panel adapt depending on the parent of the selected object. If the object is on an artboard, then the displayed X and Y are relative its placement on the artboard. However if an object is on the canvas but not on an artboard, then the displayed X and Y are relative to the global document coordinate space.
sceneNode.globalBounds provides the X and Y coordinates of a node relative to the global document, which includes the entire canvas (the grey area plus any artboards). So to get the coordinates of a node relative to its parent artboard, you need to subtract the artboard’s globalBounds coordinates.
Took me 2 years to reply back!
Thank you @DavidXD,
i used your formula and it worked:
let x = Math.round(nodeInsideArtboard.globalBounds.x) - Math.round(artboard.globalBounds.x);
let y = Math.round(nodeInsideArtboard.globalBounds.y) - Math.round(artboard.globalBounds.y);
and it gave me the positive coordinates relative to artboard.