Get x/y-coordinates from selection

Hey,
thats probably a very easy question, but anyway - I would like to get the x- and y-coordinates out of my selected object.
When I say selection.items[0] than I get this - for example:

[ Rectangle (‘Rechteck 1’) {
width: 633, height: 248
global X,Y: 251, 243
parent: Artboard (‘Web 1920 – 1’)
stroke: ff707070
fill: ffe44444
} ]

now I get everything out of this object execpt the “gobal X,Y”…

Thanks for any ideas! :pray:

2 Likes

Hi @Jojo,

please have a look at the scenegraph documentation. Each SceneNode, among other properties, has localBounds, boundsInParent and globalBounds, which are objects with x, y, width and height.

Take a look at https://adobexdplatform.com/plugin-docs/reference/core/coordinate-spaces-and-units.html. Adobe XD uses (and, through the APIs, exposes) multiple coordinate systems. Depending on which you want, you then can access it using node.xyBounds.x and node.xyBounds.y (here, replace xy with local, global or whatever else you need.

// a "full" example
const selection = require('scenegraph').selection;

for (let node of selection.items) {
  console.log(node.localBounds.x, node.localBounds.y);
}

I hope this helps,
Best,
Pablo

1 Like

Hey Pablo,
thanks for helping me again! :pray: :upside_down_face:

The .globalDrawBounds.x gets me what I needed - so thanks for the hint!
(I will try to read the docs more carefully! :innocent: )

Best,
Jojo

1 Like

We have a free tool for accessing this kind of per-node API information in a panel you can download and install:

which leads (on the right sidebar) to a direct install link

https://xd.adobelanding.com/en/xd-plugin-download/?name=6440ed65

Hope this is helpful.

1 Like