-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaveDefaultPNGByIndividualAndVisibleLayers.jsx
More file actions
49 lines (42 loc) · 1.24 KB
/
saveDefaultPNGByIndividualAndVisibleLayers.jsx
File metadata and controls
49 lines (42 loc) · 1.24 KB
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
const folder = Folder.selectDialog("エクスポート先のフォルダを選択してください");
const document = app.activeDocument;
if(document && folder) {
const options = new ExportOptionsPNG24();
options.antiAliasing = true;
options.transparency = true;
options.artBoardClipping = true;
const visibleLayers = getVisibleLayers();
for(var i = 0; i < visibleLayers.length; ++i) {
hideAllLayers();
var layer = visibleLayers[i];
layer.visible = true;
var file = new File(folder.fsName+"/"+layer.name+".png");
document.exportFile(file,ExportType.PNG24,options);
}
showAllLayers();
}
function getVisibleLayers() {
var visibleLayers = [];
forEach(document.layers, function(layer) {
if(layer.visible) {
visibleLayers.push(layer);
}
});
return visibleLayers;
}
function hideAllLayers() {
forEach(document.layers, function(layer) {
layer.visible = false;
});
}
function showAllLayers() {
forEach(document.layers, function(layer) {
layer.visible = true;
});
}
function forEach(collection, fn) {
const length = collection.length;
for(var i = 0; i < length; ++i) {
fn(collection[i]);
}
}