Known bug getting x,y coordinates of rectangles within frames (but not groups)?

I’m nearly done with my plugin, but need to access the x,y coordinates of RECTANGLE nodes that contain images. For some reason, I can access the coordinates of RECTANGLES within groups, but not frames. Unsure why this would be the case. Is this a known bug? Is there a workaround?

for (let i = 0; i < nodes.length; i++)
    {
      for (const paint of nodes[i].fills) {
        if (paint.type === 'IMAGE' && nodes[i].name.includes('Screen')) {
          ++counter;
          if(msg.checked === true) {
            const screenshotStar = figma.createStar();
            figma.currentPage.appendChild(screenshotStar);
            screenshotStar.x = nodes[i].x - 50;
            screenshotStar.y = nodes[i].y - 70;
            screenshotStar.name = "Screenshot Here";
            screenshotStar.fills = [{ type: 'SOLID', color: {r: 1, g: 0, b: 0} }];
            screenshotStar.strokes = [{ type: 'SOLID', color: {r: 1, g: 1, b: 1} }];
            screenshotStar.strokeWeight = 10;
            screenshotStar.resizeWithoutConstraints(150,150);
          }
          figma.ui.postMessage(counter);
       }
      }
    

What specifically is not working for you? You can get X and Y coordinates of nodes just fine no matter where they are placed. However note, that if the object is in a group, its coordinates will be relative to the first parent frame or canvas if there are no frames. If the object is directly in a frame, its coordinates are relative to the frame. You can get the absolute ones relative to the canvas if necessary via node.absoluteTransform.

Yes, that’s the problem. They are relative to the frame. Let me try the node.absoluteTransform property.

Works like a charm:

let newNode = nodes[i].absoluteTransform;
screenshotStar.x = newNode[0][2] - 50;
screenshotStar.y = newNode[1][2] - 50;
1 Like