SketchAPI icon indicating copy to clipboard operation
SketchAPI copied to clipboard

Expose boolean operations on ShapePath

Open KevinGutowski opened this issue 6 years ago • 1 comments

Right now you have to drop down to the private api to do this

let sketch = require('sketch')

let document = sketch.getSelectedDocument()
let selectedLayer = document.selectedLayers.layers[0]

console.log(selectedLayer.sketchObject.booleanOperation())

KevinGutowski avatar Jul 31 '19 08:07 KevinGutowski

Up for this one.

More context: in order to create a boolean group, we have to perform more actions:

  1. Create a Shape (which will become the group for the items)
let shapeGroup = new Shape({
    frame: {
        x: layer.frame.x,
        y: layer.frame.y,
        width: layer.frame.width,
        height: layer.frame.height,
    },
    name: "Name",
    parent: someParent,
    layers: [],
});
  1. Add each layer to the shapeGroup (based on selection or other lists) and apply the boolean option we need:
document.selectedLayers.layers.forEach((inner) => {
    inner.parent = shapeGroup;
    inner.sketchObject.setBooleanOperation(0);
});

where 0 = Union 1 = Substract 2 = Intersect 3 = Difference -1 = None

matteogratton avatar Jul 14 '22 10:07 matteogratton