-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfill.jsx
73 lines (71 loc) · 2.39 KB
/
fill.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include 'lib.jsx'
var doc = app.activeDocument;
var counter = 0;
doc.suspendHistory('Fill sync', 'exec()');
function queryLinkID(l){
var m = /#(.+)$/.exec(l.name);
if (!m) return;
m = /fill\(([^)]+)\)/.exec(m[1]);
if (!m) return;
return m[1];
}
var __glporl = null;
function getLastPathOnRasterLayer() {
if (__glporl) return __glporl;
var al = doc.activeLayer;
var l = doc.artLayers.add();
doc.activeLayer = l;
if (doc.pathItems.length == 0)
__glporl = null;
else
__glporl = doc.pathItems[doc.pathItems.length - 1];
doc.activeLayer = al;
l.remove();
return __glporl;
}
function handleLayers(layers, id) {
map(layers, function(l) {
var i = queryLinkID(l);
if (i != id) {
if (l.typename == 'LayerSet')
handleLayers(l.layers, id);
return;
}
doc.activeLayer = l;
l.allLocked = false;
// NOTE: unique vector will appears if "Shape" layer selected.
var path = doc.pathItems[doc.pathItems.length - 1];
if (path != getLastPathOnRasterLayer()) {
var color = app.foregroundColor;
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( stringIDToTypeID('contentLayer'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc.putReference( charIDToTypeID('null'), ref );
var fillDesc = new ActionDescriptor();
var colorDesc = new ActionDescriptor();
colorDesc.putDouble( charIDToTypeID('Rd '), color.rgb.red );
colorDesc.putDouble( charIDToTypeID('Grn '), color.rgb.green );
colorDesc.putDouble( charIDToTypeID('Bl '), color.rgb.blue );
fillDesc.putObject( charIDToTypeID('Clr '), charIDToTypeID('RGBC'), colorDesc );
desc.putObject( charIDToTypeID('T '), stringIDToTypeID('solidColorLayer'), fillDesc );
executeAction( charIDToTypeID('setd'), desc, DialogModes.NO );
}
else
doc.selection.fill(app.foregroundColor, ColorBlendMode.NORMAL, 100, true);
counter++;
});
}
function exec() {
var active = doc.activeLayer;
var id = queryLinkID(active);
var w = unitToNr(doc.width);
var h = unitToNr(doc.height);
doc.selection.select([[0, 0], [w, 0], [w, h], [0, h], [0, 0]]);
if (!id) {
alert('Fill ID does not found: fill(ID)');
return;
}
handleLayers(doc.layers, id);
doc.selection.deselect();
alert(counter + ' layers were filled');
}