简体   繁体   中英

Get width of selected layer with Sketch API

Writing my first Sketch plugin and I'm trying to get the width of a selected layer.

export default function(context) {
  const selectedLayers = context.selection;
  const selectedCount = selectedLayers.length;

  if (selectedCount === 0) {
    context.document.showMessage('Please select a circle shape layer');
  } else {
    selectedLayers.forEach(function (layer) {
      log(layer.frame.width);
    })
  }
}

The log shows:

<MOUndefined: 0x6040000048f0>

The documentation states that the frame of the layer is a Rectangle and that a Rectangle has x, y, width and height properties. So I don't understand why I'm getting undefined.

I tried log(layer.frame) and I do get:

<MOMethod: 0x60400263b420 : target=0x7f9dbf5b8ee0<MSShapeGroup: 0x7f9dbf5b8ee0> Oval (691540C6-7B18-4752-9BA6-A3A298754C9A), selector=frame>

So I'm targetting it right.

尝试

layer.frame().width()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM