Property absoluteRect is removed on app v97

Today I updated to beta version 97 and property absoluteRect is removed.
How to fix it.
And I can not export header files from class-dump.I try to dump header and check other version.Only beta version can not dump.

This is my class-dump version.

If you’re talking about -[MSLayer absoluteRect] then the following function would be a decent replacement:

function absoluteRectForLayer(layer) {
    // NOTE: the code below assumes that `layer` is anything but MSPage instance
    let parent = layer.parentObject()
    let relativeRect = layer.frame().rect()
    return parent.convertRect_toCoordinateSpace_(relativeRect, /* to absolute/page coordinates */nil)

For -[MSLayer absoluteInfluenceRect] see a sibling topic: absoluteInfluenceRect removed in Sketch 96.

1 Like

@rodionovd any ideas on how can this be translated to be used through the Javascript API? So far i 've managed to find the parent and the relative rect
let parent = layer.sketchObject.parentObject(); let relativeRect = layer.sketchObject.frame().rect(); parent.changeBasis({from: relativeRect, to: null});
and after searching found changeBasis which unfortunately doesn’t work/


If you want to stick to the official Sketch JS API, calculating a given layer’s absolute rect could be done as follows:

// this example takes a currently selected layer as an input
const doc = require('sketch/dom').getSelectedDocument()
const layer = doc.selectedLayers.layers[0]

let relative = layer.frame
let absolute = relative.changeBasis({ from: layer.parent })

Note that we pass selected.parent as a from argument for changeBasis() since a layer’s relative frame is actually in its parent coordinate space.

@rodionovd i used the code u provided, but got ‘Struct CGRect has no member named Symbol.toPrimitive’, i seems convertRect_toCoordinateSpace_ doesn,t work. i am using sketch 98.3

Both code snippets still work for me as of 98.3. Do you mind sharing your code that produces the error?

i fixed the problem,ur code snippets works。
But i have another problem, i used code like

layerObject.absoluteRect().x = newX;
layerObject.absoluteRect().y = newY;
layerObject.absoluteRect().width = newWidth;
layerObject.absoluteRect().height = newHeight;

to change the coordinate space of layer, what is new way to do this in sketch above 95.1

I guess one way to solve this is to go in the opposite direction and convert your given absolute frame to a relative one, then assign this relative frame to a layer:

function setAbsoluteRectForMSLayer(layer, newAbsoluteRect) {
  let parent = layer.parentObject()
  if (!parent.convertRect_fromCoordinateSpace) {
  let newRelativeRect = parent.convertRect_fromCoordinateSpace(newAbsoluteRect, nil)

let layer = ... // an MSLayer
// print(layer.frame()) => {0, 0, 90, 90}
// print(absoluteRectForLayer(layer)) => {100, 100, 90, 90}

let newAbsoluteRect = NSMakeRect(135, 120, 90, 90)
setAbsoluteRectForMSLayer(layer, newAbsoluteRect)

// print(layer.frame()) => {35, 20, 90, 90}