Skip to main content
Solved

Wrong positioning for frame selection inside a section

  • November 30, 2022
  • 1 reply
  • 597 views

Boris_Kirov

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.

Best answer by JosephxBrick

Hi!

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];
...
View original

1 reply

JosephxBrick
  • New Participant
  • 67 replies
  • Answer
  • November 30, 2022

Hi!

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];
...

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings