Welcome to the forum!
One way to fix this code is to use a small helper function to convert a layer’s relative frame to absolute coordinates. There’s also a no-longer available setConstrainProportions
API call that we might just get rid of entirely:
+// https://forum.sketch.com/t/property-absoluterect-is-removed-on-app-v97/1176
+function absoluteRectForLayer(layer) {
+ let parent = layer.parentObject();
+ let relativeRect = layer.frame().rect();
+ return parent.convertRect_toCoordinateSpace_(relativeRect, nil);
+}
var doc = context.document;
var selection = context.selection;
if (selection.count() > 0) {
var loopSelection = selection.objectEnumerator();
var layer;
while (layer = loopSelection.nextObject()) {
if (layer.class() != "MSArtboardGroup" && layer.class() != "MSSymbolMaster") {
var artboard = MSArtboardGroup.alloc().init();
artboard.setName(layer.name());
- artboard.setFrame(MSRect.alloc().initWithRect(layer.absoluteRect().rect()));
+ artboard.setFrame(MSRect.alloc().initWithRect(absoluteRectForLayer(layer)));
doc.currentPage().addLayers([artboard]);
- artboard.frame().setConstrainProportions(false);
layer.moveToLayer_beforeLayer(artboard, nil);
if (layer.class() == "MSLayerGroup") {
var layerGroup = artboard.layers().firstObject();
layerGroup.ungroup();
}
}
}
}