-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathmain.js
48 lines (39 loc) · 1.21 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const Dialogs = require('./helpers/dialogs')
function isArtboard(node) {
return node.constructor.name === "Artboard"
}
function artboards(nodes) {
return nodes.filter(node => isArtboard(node))
}
function metaArtboards(nodes) {
const artB = artboards(nodes)
return artB.map(artboard => {
return {
artboard,
left: artboard.globalBounds.x,
top: artboard.globalBounds.y,
right: artboard.globalBounds.x + artboard.globalBounds.width,
bottom: artboard.globalBounds.y + artboard.globalBounds.height
}
})
}
function sequelize(selection, documentRoot) {
const boards = metaArtboards(documentRoot.children);
if (!boards.length) {
return Dialogs.alert('No artboards are in document, please create some artboards.')
}
boards.sort(function (a, b) {
return a.top == b.top ? a.left - b.left : a.top - b.top;
});
boards.forEach((board, i) => {
let newName = board.artboard.name.trim()
newName = newName.replace(/[0-9.\- ]*/sm, '').trim();
newName = `${i + 1}. ${newName}`;
board.artboard.name = newName;
});
}
module.exports = {
commands: {
sequelize
}
};