-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorPoz.hx
66 lines (54 loc) · 1.42 KB
/
ColorPoz.hx
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
import Global.*;
using helpers.Document;
using helpers.Artboard;
using helpers.StringSketch;
using helpers.Layer;
import helpers.UI;
class ColorPoz
{
var hexSelected:String;
var hex:String;
function new()
{
log("ColorPoz");
try
hexSelected=selection.firstObject().style().fills().firstObject().color().hexValue()
catch (message:Dynamic)
return UI.alert("please select a colored object and do it again :)");
hex=doc.askForUserInput("replace all colored like #"+hexSelected+ "with:",0,"cc3300");
log( hex);
for ( p in doc.pages())
for (arts in p.artboards())
for (layer in arts.layers()){
loop(layer);
}
log("done");
}
function loop(layer:MSLayer)
{ if(!layer.isGroup())return swapcolor(layer,hexSelected,hex);
for ( l in layer.layers())
loop( l);
}
function swapcolor(l:MSLayer,inCol:String,outCol:String)
{
//_trace("swap");
var fill= l.style().fills().firstObject();
var fillCol=fill.color();
if( fillCol.hexValue().toString() == inCol){
log( "match="+fillCol.hexValue());
fill.setColor(MSColor.colorWithHex(outCol,fillCol.alpha()));
}
var borders=l.style().borders();
if( borders.length>0){
var border=borders.firstObject();
var bordCol=border.color();
//_trace( bordCol );
if(bordCol.hexValue().toString() ==inCol)
border.setColor(MSColor.colorWithHex(outCol,bordCol.alpha()));
}
}
static public function main()
{
var app = new ColorPoz();
}
}