-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathPNG_exporter.jsx
132 lines (117 loc) · 3.53 KB
/
PNG_exporter.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
function getConfig(dok, px) {
//var mainWindow = new Window("dialog", px.projectName + " – " + px.version, undefined, { resizeable: true });
var doc = activeDocument;
var mainWindow = new Window("dialog", px.projectName , undefined, { resizeable: true });
var filepath = doc.path;
filePanel = mainWindow.add("Panel", undefined, "File Panel");
filePanel.alignment = ["fill", "fill"];
filePanel.margins = [10, 20, 10, 10];
filePanel.alignChildren = ["left", "top"];
var folderPath = filePanel.add("edittext", undefined, doc.path + '/');
folderPath.preferredSize.width = 200;
var controlGroup = mainWindow.add("group");
controlGroup.orientation = "row";
controlGroup.alignment = "fill";
controlGroup.alignChildren = ["right", "center"];
controlGroup.orientation = "row";
controlGroup.alignment = "fill";
with (controlGroup) {
//var goToWebsite = controlGroup.add("button", undefined, "by grefel");
//var divider = controlGroup.add("panel");
//divider.alignment = "fill";
var closeButton = controlGroup.add("button", undefined, "Cancel");
var folderButton = controlGroup.add("button", undefined, "Select");
var okButton = controlGroup.add("button", undefined, "Convert");
}
folderButton.onClick = function () {
alert (filepath);
var myDefault = new Folder (filepath);
alert (myDefault);
var myFolder = myDefault.selectDlg("Select a folder to process",'',true);
folderPath.text = myFolder;
}
okButton.onClick = function () {
imgConvert(folderPath.text.toString());
alert ('Done!');
}
closeButton.onClick = function () {
mainWindow.close();
}
mainWindow.center();
var res = mainWindow.show();
if (res === 1) {
return true;
}
else {
return false;
}
}
function readJson(path) {
var currentLine;
var jsonStuff = [];
fileInput = new File(path);
fileInput.open("r");
while(!fileInput.eof) {
currentLine = fileInput.readln();
jsonStuff.push(currentLine);
}
fileInput.close();
jsonStuff = jsonStuff.join("");
var parsedJson = JSON.parse(jsonStuff);
return parsedJson;
}
function hideAllLayers(doc){
for(var i=0;i<doc.layers.length;i++){
curLayer = doc.layers[i];
curLayer.visible = false;
if(curLayer.typename =='LayerSet'){
hideAllLayers(curLayer)
}
}
}
function dfs(expPath,doc) {
for(var i=0;i<doc.layers.length;i++){
curLayer = doc.layers[i];
if(curLayer.typename =='LayerSet'){
curLayer.visible = true;
var f = new Folder(expPath + curLayer.name);
if ( ! f.exists ) {
f.create()
}
dfs(expPath+ curLayer.name +'\\',curLayer)
}
else {
curLayer.visible = true;
var opts, file;
opts = new ExportOptionsSaveForWeb();
opts.format = SaveDocumentType.PNG;
opts.PNG8 = false;
opts.quality = 100;
pngFile = new File(expPath + curLayer.name + '.png');
app.activeDocument.exportDocument(pngFile, ExportType.SAVEFORWEB, opts);
curLayer.visible = false;
}
}
}
function imgConvert(expPath){
var doc = activeDocument;
dfs (expPath,doc);
}
start();
function start() {
var px = {
projectName: "Png Exporter",
processText: true,
clearParagraphStyle: "[All]",
clearCharacterStyle: "[All]",
processTables: false,
clearTableStyle: "[All]",
processObjects: false,
clearObjectStyle: "[All]",
}
var dok = '';
if (!getConfig(dok, px)) {
// User cancelled
return;
}
}