-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
PS_BRAMUS.TextConvert.Export.jsx
164 lines (124 loc) · 4.66 KB
/
PS_BRAMUS.TextConvert.Export.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*****************************************************************
*
* TextConvert.Export 1.1 - by Bramus! - https://www.bram.us/
*
* v 1.1 - 2016.02.17 - UTF-8 support
* Update license to MIT License
*
* v 1.0 - 2008.10.30 - (based upon TextExport 1.3, without the "save dialog" option)
*
*****************************************************************
*
* Copyright (c) 2016 Bram(us) Van Damme - https://www.bram.us/
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*****************************************************************/
/**
* TextConvert.Export Init function
* -------------------------------------------------------------
*/
function initTextConvertExport() {
// Linefeed shizzle
if ($.os.search(/windows/i) != -1)
fileLineFeed = "windows";
else
fileLineFeed = "macintosh";
// Do we have a document open?
if (app.documents.length === 0) {
alert("Please open a file", "TextConvert.Export Error", true);
return;
}
// Oh, we have more than one document open!
if (app.documents.length > 1) {
var runMultiple = confirm("TextConvert.Export has detected Multiple Files.\nDo you wish to run TextConvert.Export on all opened files?", true, "TextConvert.Export");
if (runMultiple === true) {
docs = app.documents;
} else {
docs = [app.activeDocument];
}
// Only one document open
} else {
runMultiple = false;
docs = [app.activeDocument];
}
// Loop all documents
for (var i = 0; i < docs.length; i++)
{
// Auto set filePath and fileName
filePath = Folder.myDocuments + '/TextConvert-' + docs[i].name + '.txt';
// create outfile
var fileOut = new File(filePath);
// set linefeed
fileOut.linefeed = fileLineFeed;
// Set encoding
fileOut.encoding = "UTF8"
// open for write
fileOut.open("w", "TEXT", "????");
// Set active document
app.activeDocument = docs[i];
// call to the core with the current document
goTextExport2(app.activeDocument, fileOut, '/');
// close the file
fileOut.close();
}
// Post processing: give notice (multiple) or open file (single)
if (runMultiple === true) {
alert("Parsed " + documents.length + " files;\nFiles were saved in your documents folder", "TextExport");
} else {
fileOut.execute();
}
}
/**
* TextExport Core Function (V2)
* -------------------------------------------------------------
*/
function goTextExport2(el, fileOut, path)
{
// Get the layers
var layers = el.layers;
// Loop 'm
for (var layerIndex = layers.length; layerIndex > 0; layerIndex--)
{
// curentLayer ref
var currentLayer = layers[layerIndex-1];
// currentLayer is a LayerSet
if (currentLayer.typename == "LayerSet") {
goTextExport2(currentLayer, fileOut, path + currentLayer.name + '/');
// currentLayer is not a LayerSet
} else {
// Layer is visible and Text --> we can haz copy paste!
if ( (currentLayer.visible) && (currentLayer.kind == LayerKind.TEXT) )
{
fileOut.writeln('');
fileOut.writeln('');
fileOut.writeln('');
fileOut.writeln('');
fileOut.writeln('[BEGIN ' + path + currentLayer.name + ' ]');
fileOut.writeln(currentLayer.textItem.contents);
fileOut.writeln('[END ' + path + currentLayer.name + ' ]');
}
}
}
}
/**
* TextConvert.Export Boot her up
* -------------------------------------------------------------
*/
initTextConvertExport();