SketchAPI
SketchAPI copied to clipboard
Flatten Selection To Bitmap
Is there an api do something like “Flatten Selection To Bitmap” ?
Thank you for planning to add the api as enhancement 。 Could you give some suggestions of how to implement it, I really need it。
@zjuwjf You can try this:
const layers = document.selectedLayers.layers
const layer = layers[0]
const flattener = MSLayerFlattener.alloc().init();
flattener.flattenLayers(MSLayerArray.arrayWithLayers([layer.sketchObject]));
It works, so cool! @nichenqin
Thinking a bit about it, I think we want a top-level method flatten
similar to export
.
It would take either a single layer or an array of layers and return an Image
Can it return an Image
? The flatten behavior looks not synchronous
Indeed you are right. I'm wondering if we could return it in a callback or something. Will have to look at the code
Hi @mathieudutour, is there any update on this? Or is there any other similar way to synchronously get a flattened image?
I'm curious because I just want to name the resulting Bitmap layer. Setting it only ends up getting overwritten, because it's asynchronous, as you know.
Thank you!