SketchAPI icon indicating copy to clipboard operation
SketchAPI copied to clipboard

Flatten Selection To Bitmap

Open zjuwjf opened this issue 6 years ago • 7 comments

Is there an api do something like “Flatten Selection To Bitmap” ?

zjuwjf avatar Mar 15 '18 06:03 zjuwjf

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 avatar Mar 19 '18 01:03 zjuwjf

@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]));

nichenqin avatar Mar 19 '18 02:03 nichenqin

It works, so cool! @nichenqin

zjuwjf avatar Mar 19 '18 06:03 zjuwjf

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

mathieudutour avatar Mar 23 '18 07:03 mathieudutour

Can it return an Image? The flatten behavior looks not synchronous

nichenqin avatar Mar 23 '18 09:03 nichenqin

Indeed you are right. I'm wondering if we could return it in a callback or something. Will have to look at the code

mathieudutour avatar Mar 23 '18 15:03 mathieudutour

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!

jayliu50 avatar Aug 22 '20 19:08 jayliu50