-
Notifications
You must be signed in to change notification settings - Fork 0
/
fillall.jsx
52 lines (50 loc) · 1.36 KB
/
fillall.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include 'lib.jsx'
var doc = app.activeDocument;
var al = doc.activeLayer;
var affected = 0;
var notfound = {};
doc.suspendHistory('Fill sync (All)', 'exec()');
function handleLayers(layers, pal) {
for (var c = 0; c < layers.length; c++) {
var l = layers[c];
if (l.typename == 'ArtLayer') {
var instr = parseInstructions(l.name);
if (!instr || !instr['fill']) return;
var id = instr['fill'];
if (!id) continue;
var color = pal[id];
if (!color) {
if (notfound[id]) notfound[id] ++;
else notfound[id] = 1;
continue;
}
doc.activeLayer = l;
doc.activeLayer.pixelsLocked = false;
doc.activeLayer.transparentPixelsLocked = false;
doc.selection.deselect();
doc.selection.fill(color, ColorBlendMode.NORMAL, 100, true);
affected++;
}
else if (l.typename == 'LayerSet') {
if (plsname.test(l.name)) continue;
handleLayers(l.layers, pal);
}
}
}
function exec() {
var pal;
try {
pal = parsePaletteLayerSet(pls);
}
catch(e) {
alert(e);
return;
}
handleLayers(pls.parent.layers, pal);
alert(affected + ' layers had been filled');
var warn = [];
for (var p in notfound)
warn.push([p, '(', notfound[p], ')'].join(''));
if (warn.length > 0 )
alert('WARNING: following colors are not defined in #palette: ' + warn.join(', '));
}