Wrong positioning for frame selection inside a section

Hello, I have this simple plugin which allows me to generate a frame with text object below a selection, it can be a text, frame, rectangle etc. It works perfectly fine, but when I have a frame inside a section, the positioning is completely wrong. I was wondering why can this be the case?

This is what I do to grab the selection:
const selectionX = node.x; const selectionY = node.y; const selectionWidth = node.width; const selectionHeight = node.height; const selectionName = node.name;

This is what I do the position the created frame below the selection:

auto.x = selectionX; auto.y = selectionY + selectionHeight + 32;

Actually same happens when I have a frame inside a frame, and I select the inner frame it break and places the items way below. My assumption is becase the inner frame has different x,y because the parent frame acts like a canvas. Let me know if you know something around those cases, I found it very interesting.


You can get the absolute position of a node relative to the page rather than relative to its parent(s) using the node’s absoluteTransform. Change your code to the following:

const transform = node.absoluteTransform as Transform;
const selectionX = transform[0][2];
const selectionY = transform[1][2];