SketchAPI
SketchAPI copied to clipboard
Expose boolean operations on ShapePath
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())
Up for this one.
More context: in order to create a boolean group, we have to perform more actions:
- 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: [],
});
- 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