That's amazing! ๐
I believe this is referring to the .getDocument() method of a library? I also couldn't find the PR that added this.
Indeed, previously when you used library.getDocument()
the path
of the Document would be undefined. It's now set correctly. That's the PR: https://github.com/BohemianCoding/SketchAPI/pull/265
No need to specify the type when there is no choice (like Document.pages can only contain Pages, Layer.exportFormats can only contain ExportFormats, etc.)"
That's shouldn't affect anybody. Pretty much every object from the JS API is a wrapper around a native object (like ExportFormats
is a wrapper around MSExportFormat
). The way the API works when creating a new wrapper is that it looks at the type
field to create the underlying native object. But in some cases, there is no choices: the objects inside exportFormats
will always be MSExportFormat
.
So instead of layer.exportFormats = [{type: 'ExportFormat, size: '2x'}]
, you can just write layer.exportFormats = [{size: '2x'}]
.
You can also use the parent property on Layer that was added to go up the layer structure.
It has always been there but it's not enumerated to avoid circular references ๐
pretty sure there is a floating point error here when you set this through the UI
I'm not sure I understand, this sounds like a bug maybe?
would be nice to get the default since it varies from each font
Good point: https://github.com/BohemianCoding/SketchAPI/pull/318
Things that I couldn't get to work
Could you be more specific? This works fine for me:
const sketch = require('sketch')
const slice = new sketch.Slice({
parent: sketch.getSelectedDocument().selectedPage,
exportFormats: [
{
size: '2x',
suffix: '@2x',
},
],
})
console.log(slice)
There are a few more things with the new beta (did I forget them in the changelog?):
- setTimeout
and all the other timeout, interval, immediate methods are now available directly, no need to polyfill them.
- new method on the path
module require('path').resourcePath(string)
which returns the path to a resource in the plugin bundle or undefined
if it doesn't exist.
There are a few more things coming in the next betas:
- artboard.background
- layer.transform
- export(layer, {formats: ['json']})
which returns the JSON format of a layer
- A lot more on ShapePath
: points
, shapeType
, closed
, shapePath.getSVGPath()
, ShapePath.fromSvgPath(path)
- the arrays will now work as expected: previously if you did something like group.layers.push({type: 'Text'})
, it wouldn't add a new layer because the array was mutated but the parent wasn't aware of it. It will now add a layer as expected.
Thanks again for all of this!