Hello, I have a question about selecting all shape layers with javascript.
I tried with the code below, but it takes too long to try on a file with many artboards and many layers.
var sketch = require('sketch')
var document = sketch.getSelectedDocument();
var selectedPage = document.selectedPage;
var shapeLayers = []
var nativeLayers = selectedPage.sketchObject.children();
nativeLayers.forEach(nativelayer => {
var layer = sketch.fromNative(nativelayer);
if (layer.type == 'Shape' || layer.type == 'ShapePath') {
shapeLayers.push(layer)
layer.selected = true;
}
});
console.log(shapeLayers.length)
So I want to optimize the code to save time, is there a good way?
Thank you in advance.