-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSeperateToLayersFast.js
71 lines (60 loc) · 1.44 KB
/
SeperateToLayersFast.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//The MIT License(MIT)
//Copyright(c) 2015 Andrew Armbruster
//Please read included LICENSE for license agreement
displayDialogs = DialogModes.NO;
saveOptions = new PNGSaveOptions();
var AD = activeDocument;
start();
function start()
{
if(!AD.saved)
{
alert("Please save your document");
return;
}
seperateLayers();
}
function seperateLayers()
{
if (documents.length != 0)
{
var outputFolder = Folder.selectDialog("Select a folder for the output files")
if(outputFolder == null){ return; }
var checkArray = new Array(AD.layers.length);
for(a = 0; a < AD.layers.length; a++)
{
var currentLayer = AD.layers[a];
if(!((currentLayer.kind == LayerKind.TEXT)||(currentLayer.kind == LayerKind.NORMAL)||(currentLayer.kind == LayerKind.LayerSet)) && currentLayer.visible != 0)
{
checkArray[a] = 0;
}
else
{
checkArray[a] = 1;
}
if(AD.layers[a].length <= 1)
{
alert("You only have one layer, is this really necessary?");
}else{
AD.layers[a].visible = 0;
}
}
for(a = 0; a < AD.layers.length; a++)
{
if(checkArray[a] == 1)
{
AD.layers[a].visible = 1;
newFile = new File(outputFolder+"/("+(a)+")_"+AD.layers[a].name+".png");
AD.saveAs (newFile,saveOptions, true, Extension.LOWERCASE);
}
if(AD.layers[a].length <= 1)
{
AD.layers[a].visible = 1;
}
}
for(a = 0; a < AD.layers.length; a++)
{
AD.layers[a].visible = checkArray[a];
}
}
}