forked from ff6347/mpolauncherJSRes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFind Items.jsx
301 lines (235 loc) · 7.56 KB
/
Find Items.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
// this looks for script labels made by the importer
// just write in some code and run it
// Copyright (C) 2011 Fabian "fabiantheblind" Morón Zirfas
// http://www.the-moron.net
// info [at] the - moron . net
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/.
//alert($.fileName);
main();
function main () {
var d;
// test for a doc
try { var d = app.activeDocument; } catch(e){
alert("No no no, you have no document.\nMaybe you should drink some coffee");
return;
}
// mix your own black
try{
c = myColorAdd( d, "ERROR", ColorModel.PROCESS, [0,100,100,0]);
}catch (e){
c = d.swatches.item("ERROR"); // this is THE MIXED BLACK
}
// Create a list of swatches
var list_of_swatches = d.swatches.everyItem().name;
var api = d.allPageItems;
var list = new Array();
var strlist = new Array();
var target;
var choice;
var marker;
var select;
var rmvLabel;
var edit;
var editStr;
for( var i = 0; i < api.length; i++ ){
// if( api[i].label.length > 1){
list[i] = api[i].label;
// }
}
strlist = eliminateDuplicates(list);
// remove the last item in the list
// it is from the objects without a label
strlist.pop();
strlist = sort_obj_names(strlist);
//alert(strlist);
// Make dialog box for selecting the swatch
var dlg = app.dialogs.add({name:"The Item Finder", canCancel:true});
with(dlg) {
with(dialogColumns.add()){
with(dialogRows.add()){
//staticTexts.add({staticLabel:"Articles:"});
}
with(dialogRows.add()){
var selected_item = dropdowns.add({stringList:strlist, selectedIndex:0});
}
with(dialogRows.add()){
var addMarkerChkBx = checkboxControls.add({checkedState:true, staticLabel:"add marker 2 items?"});
}
// with(dialogRows.add()){
// staticTexts.add({staticLabel: " "});
// }
with(dialogRows.add()){
var add2SelChkBx = checkboxControls.add({checkedState:false, staticLabel:"add items to selection?"});
}
with(dialogRows.add()){
var delItemChkBx = checkboxControls.add({checkedState:false, staticLabel:"delete selected items?"});
}
with(dialogRows.add()){
var rmvItemLblChkBx = checkboxControls.add({checkedState:false, staticLabel:"remove selected labels?"});
}
// with(dialogRows.add()){
// staticTexts.add({staticLabel: " "});
// }
with(dialogRows.add()){
var addTagChkBx = checkboxControls.add({checkedState:false, staticLabel:"add new tag to selection?"});
}
with(dialogRows.add()){
var txtEdit = textEditboxes.add({editContents:"", minWidth:170});
}
// with(dialogRows.add()){
// var aGutter = staticTexts.add({staticLabel:" ",minWidth:25});
// }
// with(dialogRows.add()){
// staticTexts.add({staticLabel:"Marker Color:"});
// }
// with(dialogRows.add()){
// // var ndx;
// // var j = 0;
// // while(j < list_of_swatches.length){
// // if(list_of_swatches[j].match("ERROR")){
// // ndx = j;
// // break;
// // }else{
// // ndx = 0;
// // }
// // }
// try{
// var selected_swatch = dropdowns.add({stringList:list_of_swatches, selectedIndex:d.swatches.length - 2,minWidth:200});
// }catch(e){
// var selected_swatch = dropdowns.add({stringList:list_of_swatches, selectedIndex:1,minWidth:200});
//
// }
// }
}
with(dialogColumns.add()){
var gutter = staticTexts.add({staticLabel:" ",minWidth:25});
}
}
//Display the dialog box.
if(dlg.show() == true){
target = selected_item.stringList[selected_item.selectedIndex];
choice = delItemChkBx.checkedState;
marker = addMarkerChkBx.checkedState;
select = add2SelChkBx.checkedState;
rmvLabel = rmvItemLblChkBx.checkedState;
edit = addTagChkBx.checkedState;
editStr = txtEdit.editContents;
dlg.destroy();
//alert(target);
var grp = new Array();
for( var i = api.length-1; i > 0; i -- ){
try{
var theThing = api[i];
if((choice == true) && (api[i].label.match(target))){
//list[i] = api[i].label;
theThing.remove();
continue;
}else if ((choice == false) && (api[i].label.match(target))){
if(marker){
var ov = api[i].parent.ovals.add();
set_label(ov, "_00 Finder Marker");
var apigmb = api[i].geometricBounds;
ov.geometricBounds = [apigmb[0],apigmb[1],apigmb[0]+13.23,apigmb[1]+13.23];
ov.nonprinting = true;
ov.fillColor = c;
}
if(rmvLabel){
api[i].label = "";
}
if(select){
api[i].select(SelectionOptions.ADD_TO);
}
if(marker && select){
ov.select(SelectionOptions.ADD_TO);
}
if(edit && select){
api[i].label = editStr;
api[i].select(SelectionOptions.ADD_TO);
}
}
}catch(e){};
}// end of first for loop
if(edit){
for(var j = 0; j < app.selection.length; j++){
try{
app.selection[i].label = editStr;
}catch(e){}
}
}
}else{
dlg.destroy();
}
}// end of main
//found here:
// http://stackoverflow.com/questions/840781/easiest-way-to-find-duplicate-values-in-a-javascript-array
function eliminateDuplicates(arr) {
var i,
len=arr.length,
out=[],
obj={};
for (i=0;i<len;i++) {
obj[arr[i]]=0;
}
for (i in obj) {
out.push(i);
}
return out;
}
// color functions for definatly creating the right color
// found on http://bit.ly/h5EobK indisnip.wordpress.com ->
// how to apply:
// add CMYK color
//myColorAdd(app.activeDocument, "My Custom Color", ColorModel.PROCESS, [80,50,30,10]);
// add RGB color
//myColorAdd(app.activeDocument, "My Custom Color", ColorModel.PROCESS, [33,66,99]);
// add HEX color
//myColorAdd(app.activeDocument, "My Custom Color", ColorModel.PROCESS, "ABCDEF");
// add color directly
// add CMYK color to document
// and asign it to selected object
//app.selection[0].fillColor = myColorAdd(app.activeDocument, "My Custom Color", ColorModel.PROCESS, [80,50,30,10]);
function myColorAdd(myDocument, myColorName, myColorModel, myColorValue){
if(myColorValue instanceof Array == false){
myColorValue = [(parseInt(myColorValue, 16) >> 16 ) & 0xff, (parseInt(myColorValue, 16) >> 8 ) & 0xff, parseInt(myColorValue, 16 ) & 0xff ];
myColorSpace = ColorSpace.RGB;
}else{
if(myColorValue.length == 3)
myColorSpace = ColorSpace.RGB;
else
myColorSpace = ColorSpace.CMYK;
}
try{
myColor = myDocument.colors.item(myColorName);
myName = myColor.name;
}
catch (myError){
myColor = myDocument.colors.add();
myColor.properties = {name:myColorName, model:myColorModel, space:myColorSpace ,colorValue:myColorValue};
}
return myColor;
}
function set_label(obj,str){
try{
obj.label = str;
}catch(e){
}
}
function sort_obj_names (list)
{
var array = list;
// array.shift (); array.shift (); array.shift (); array.shift (); // exclude [None], [Basic Graphics Frame], [Basic Text Frame], [Basic Grid]
return array.sort (case_insensitive);
}
function case_insensitive (a, b)
{
return a.toLowerCase() > b.toLowerCase()
}