SketchAPI icon indicating copy to clipboard operation
SketchAPI copied to clipboard

JS API export doesn’t behave as native sketch export

Open KevinGutowski opened this issue 4 years ago • 4 comments

If you have overlapping artboards the JS export will behave differently than the native sketch export. Example code:

let sketch = require('sketch')
let Artboard = sketch.Artboard
let Rectangle = sketch.Rectangle
let document = sketch.getSelectedDocument()

let page = document.pages[0]
page.layers = []

let bgArtboard = new Artboard({
  frame: new Rectangle(0,0,100,100),
  parent: page,
  background: { color: "#D0021B", enabled: true, includedInExport: true }
})

let fgArtboard = new Artboard({
  frame: new Rectangle(25,25,50,50),
  parent: page,
  background: { color: "#0000FF", enabled: true, includedInExport: true }
})

const options = { formats: 'png', output: false }
const buffer = sketch.export(bgArtboard, options).toNSData()

var pasteboard = NSPasteboard.generalPasteboard();
pasteboard.clearContents();
pasteboard.setData_forType(buffer, NSPasteboardTypePNG);

ExportBug

KevinGutowski avatar Oct 26 '19 04:10 KevinGutowski

Is this comparing the result between exporting from the (internal/cocoascript) JS API via the pasteboard vs. exporting natively/normally via the File > Export menu?

jedrichards avatar Oct 28 '19 10:10 jedrichards

Yep! Exactly! The JS export seems to grab artboards that are above it whereas the File>Export doesn’t.

KevinGutowski avatar Oct 28 '19 18:10 KevinGutowski

Hey guys, is there any update on this issue?

stt045 avatar Feb 07 '20 19:02 stt045

Quick and dirty solution is to just remove the parent of the object that you are wanting to export, export it, and then add the parent back. Just have to be careful with ordering of the layer when adding it back.

KevinGutowski avatar Feb 08 '20 02:02 KevinGutowski