-
Notifications
You must be signed in to change notification settings - Fork 0
/
autonr.jsx
33 lines (26 loc) · 950 Bytes
/
autonr.jsx
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
#include 'lib.jsx'
var doc = app.activeDocument;
var counter = 0;
doc.suspendHistory('Auto Numbering', 'exec()');
function exec() {
if (doc.activeLayer.typename != 'LayerSet') {
alert("Select layer set and reload this script");
}
var globalInstr = parseInstructions(doc.activeLayer.name);
globalInstr = globalInstr && globalInstr['autonr'] ? globalInstr['autonr'] : '';
prefix = /\bprefix\s*=\s*([^\s]+)/.exec(globalInstr);
prefix = prefix ? prefix[1] : '';
shift = /\bshift\s*=\s*([0-9]+)/.exec(globalInstr);
shift = shift ? parseInt(shift[1]) : 0;
var count= 0 + shift;
map( map(doc.activeLayer.layers, function(l) {
var instr = parseInstructions(l.name);
if (instr && instr['autonr'] && /\bskip\b/.test(instr['autonr']))
return null;
count++;
return l;
}), function(l) {
if (l)
l.name = buildName((count--).toString(), prefix, '', '');
});
}