-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageCatalog_improved.jsx
668 lines (603 loc) · 20.9 KB
/
ImageCatalog_improved.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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
//ImageCatalog.jsx
//An InDesign CS6 JavaScript
/*
@@@BUILDINFO@@@ "ImageCatalog.jsx" 3.0.0 15 December 2009
*/
//Creates an image catalog from the graphic files in a selected folder.
//Each file can be labeled with the file name, and the labels are placed on
//a separate layer and formatted using a paragraph style ("label") you can
//modify to change the appearance of the labels.
//
//For more information on InDesign scripting, go to http://www.adobe.com/products/indesign/scripting/index.html
//Or visit the InDesign Scripting User to User forum at http://www.adobeforums.com .
//
//The myExtensions array contains the extensions of the graphic file types you want
//to include in the catalog. You can remove extensions from or add extensions to this list.
//myExtensions is a global. Mac OS users should also look at the file types in the myFileFilter function.
main();
function main() {
var myFilteredFiles;
//Make certain that user interaction (display of dialogs, etc.) is turned on.
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
myExtensions = [".png", ".jpg", ".jpeg", ".eps", ".ps", ".pdf", ".tif", ".tiff", ".gif", ".psd", ".ai"];
//Display the folder browser.
var myFolder = Folder.selectDialog("Select the folder containing the images", "");
//Get the path to the folder containing the files you want to place.
if (myFolder != null) {
if (File.fs === "Macintosh") {
myFilteredFiles = myMacOSFileFilter(myFolder);
} else {
myFilteredFiles = myWinOSFileFilter(myFolder);
}
if (myFilteredFiles.length !== 0) {
myDisplayDialog(myFilteredFiles, myFolder);
alert("Done!");
}
}
}
// Edit: function indexOf
function indexOf(item1, item2) {
var indexOf = -1;
for (var i = 0; i < item1.length; i++) {
if (item1[i] == item2) {
indexOf = i;
}
}
return indexOf;
}
// Edit: Function to order an array according to another
function mapOrder(array, order) {
array.sort(function(a, b) {
var extractedFilenameA = a[1].toString().split("/");
extractedFilenameA = extractedFilenameA[extractedFilenameA.length - 1];
var extractedFilenameB = b[1].toString().split("/");
extractedFilenameB = extractedFilenameB[extractedFilenameB.length - 1];
if (indexOf(order, extractedFilenameA) > indexOf(order, extractedFilenameB)) {
return 1;
} else {
return -1;
}
});
return array;
};
//Windows version of the file filter.
function myWinOSFileFilter(myFolder) {
var myFiles = new Array;
var myFilteredFiles = new Array;
for (myExtensionCounter = 0; myExtensionCounter < myExtensions.length; myExtensionCounter++) {
myExtension = myExtensions[myExtensionCounter];
myFiles = myFolder.getFiles("*" + myExtension);
if (myFiles.length != 0) {
for (var myFileCounter = 0; myFileCounter < myFiles.length; myFileCounter++) {
myFilteredFiles.push(myFiles[myFileCounter]);
}
}
}
myFilteredFiles.sort(function(a, b) {
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
});
return myFilteredFiles;
}
// Edit: changed the return from an object to an ordered array
function myMacOSFileFilter(myFolder) {
var myFilteredFiles = myFolder.getFiles(myFileFilter);
var filePath_array = [];
var fileName_array = [];
for (var file in myFilteredFiles) {
filePath_array.push([file, myFilteredFiles[file]]);
var fileName = myFilteredFiles[file].toString().split("/");
fileName = fileName[fileName.length - 1];
fileName_array.push(fileName);
//alert(fileName);
}
fileName_array.sort(function(a, b) {
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
});
//alert(filePath_array[0][1]);
mapOrder(filePath_array, fileName_array);
//alert(filePath_array);
return filePath_array;
}
//Mac OS version of file filter
//Have to provide a separate version because not all Mac OS users use file extensions
//and/or file extensions are sometimes hidden by the Finder.
function myFileFilter(myFile) {
var myFileType = myFile.type;
switch (myFileType) {
case "PNG":
case "JPEG":
case "EPSF":
case "PICT":
case "TIFF":
case "8BPS":
case "GIFf":
case "PDF ":
return true;
break;
default:
for (var myCounter = 0; myCounter < myExtensions.length; myCounter++) {
var myExtension = myExtensions[myCounter];
if (myFile.name.indexOf(myExtension) > -1) {
return true;
break;
}
}
}
return false;
}
function myDisplayDialog(myFiles, myFolder) {
var myLabelWidth = 112;
var myStyleNames = myGetParagraphStyleNames(app);
var myLayerNames = ["Layer 1", "Labels"];
var myDialog = app.dialogs.add({ name: "Image Catalog" });
// Edit: added alignment array
/*var myAlignments = [
"Top Left",
"Top Center",
"Top Right",
"Middle Left",
"Middle Center",
"Middle Right",
"Bottom Left",
"Bottom Center",
"Bottom Right"
];*/
var myAlignments = [
"None",
"Top",
"Left",
"Right",
"Bottom"
];
with (myDialog.dialogColumns.add()) {
with (dialogRows.add()) {
staticTexts.add({ staticLabel: "Information:" });
}
with (borderPanels.add()) {
with (dialogColumns.add()) {
with (dialogRows.add()) {
staticTexts.add({ staticLabel: "Source Folder:", minWidth: myLabelWidth });
staticTexts.add({ staticLabel: myFolder.path + "/" + myFolder.name });
}
with (dialogRows.add()) {
staticTexts.add({ staticLabel: "Number of Images:", minWidth: myLabelWidth });
staticTexts.add({ staticLabel: myFiles.length + "" });
}
}
}
with (dialogRows.add()) {
staticTexts.add({ staticLabel: "Options:" });
}
with (borderPanels.add()) {
with (dialogColumns.add()) {
with (dialogRows.add()) {
staticTexts.add({ staticLabel: "Number of Rows:", minWidth: myLabelWidth });
var myNumberOfRowsField = integerEditboxes.add({ editValue: 1 });
}
with (dialogRows.add()) {
staticTexts.add({ staticLabel: "Number of Columns:", minWidth: myLabelWidth });
var myNumberOfColumnsField = integerEditboxes.add({ editValue: 1 });
}
with (dialogRows.add()) {
staticTexts.add({ staticLabel: "Horizontal Offset:", minWidth: myLabelWidth });
var myHorizontalOffsetField = measurementEditboxes.add({
editValue: 0,
editUnits: MeasurementUnits.points
});
}
with (dialogRows.add()) {
staticTexts.add({ staticLabel: "Vertical Offset:", minWidth: myLabelWidth });
var myVerticalOffsetField = measurementEditboxes.add({
editValue: 0,
editUnits: MeasurementUnits.points
});
}
with (dialogRows.add()) {
with (dialogColumns.add()) {
staticTexts.add({ staticLabel: "Fitting:", minWidth: myLabelWidth });
}
with (dialogColumns.add()) {
var myFitProportionalCheckbox = checkboxControls.add({
staticLabel: "Proportional",
checkedState: true
});
var myFitCenterContentCheckbox = checkboxControls.add({
staticLabel: "Center Content",
checkedState: true
});
var myFitFrameToContentCheckbox = checkboxControls.add({
staticLabel: "Frame to Content",
checkedState: true
});
}
}
with (dialogColumns.add()) {
//Label type
with (dialogRows.add()) {
with (dialogColumns.add()) {
staticTexts.add({ staticLabel: "Align:", minWidth: myLabelWidth });
}
with (dialogColumns.add()) {
var myAlignDropdown = dropdowns.add({
stringList: myAlignments,
selectedIndex: 0
});
}
}
}
with (dialogRows.add()) {
var myRemoveEmptyFramesCheckbox = checkboxControls.add({
staticLabel: "Remove Empty Frames",
checkedState: true
});
}
}
}
with (dialogRows.add()) {
staticTexts.add({ staticLabel: "" });
}
// Edit: new label group with added options
var myExistingDocumentGroup = enablingGroups.add({ staticLabel: "Use Existing Document", checkedState: false });
with (myExistingDocumentGroup) {
with (dialogColumns.add()) {
//Label type
// Edit: added make new document option
with (dialogRows.add()) {
var myMakeNewPagesCheckbox = checkboxControls.add({
staticLabel: "Add New Pages",
checkedState: true
});
}
}
}
with (dialogRows.add()) {
staticTexts.add({ staticLabel: "" });
}
var myLabelsGroup = enablingGroups.add({ staticLabel: "Labels", checkedState: false });
with (myLabelsGroup) {
with (dialogColumns.add()) {
//Label type
with (dialogRows.add()) {
with (dialogColumns.add()) {
staticTexts.add({ staticLabel: "Label Type:", minWidth: myLabelWidth });
}
with (dialogColumns.add()) {
var myLabelTypeDropdown = dropdowns.add({
stringList: ["File name", "File path", "XMP description", "XMP author"],
selectedIndex: 0
});
}
}
//Text frame height
with (dialogRows.add()) {
with (dialogColumns.add()) {
staticTexts.add({ staticLabel: "Label Height:", minWidth: myLabelWidth });
}
with (dialogColumns.add()) {
var myLabelHeightField = measurementEditboxes.add({
editValue: 24,
editUnits: MeasurementUnits.points
});
}
}
//Text frame offset
with (dialogRows.add()) {
with (dialogColumns.add()) {
staticTexts.add({ staticLabel: "Label Offset:", minWidth: myLabelWidth });
}
with (dialogColumns.add()) {
var myLabelOffsetField = measurementEditboxes.add({
editValue: 0,
editUnits: MeasurementUnits.points
});
}
}
//Style to apply
with (dialogRows.add()) {
with (dialogColumns.add()) {
staticTexts.add({ staticLabel: "Label Style:", minWidth: myLabelWidth });
}
with (dialogColumns.add()) {
var myLabelStyleDropdown = dropdowns.add({ stringList: myStyleNames, selectedIndex: 0 });
}
}
//Layer
with (dialogRows.add()) {
with (dialogColumns.add()) {
staticTexts.add({ staticLabel: "Layer:", minWidth: myLabelWidth });
}
with (dialogColumns.add()) {
var myLayerDropdown = dropdowns.add({ stringList: myLayerNames, selectedIndex: 0 });
}
}
}
}
var myResult = myDialog.show();
if (myResult == true) {
var myNumberOfRows = myNumberOfRowsField.editValue;
var myNumberOfColumns = myNumberOfColumnsField.editValue;
var myRemoveEmptyFrames = myRemoveEmptyFramesCheckbox.checkedState;
var myFitProportional = myFitProportionalCheckbox.checkedState;
var myFitCenterContent = myFitCenterContentCheckbox.checkedState;
var myFitFrameToContent = myFitFrameToContentCheckbox.checkedState;
var myHorizontalOffset = myHorizontalOffsetField.editValue;
var myVerticalOffset = myVerticalOffsetField.editValue;
var myMakeLabels = myLabelsGroup.checkedState;
var myLabelType = myLabelTypeDropdown.selectedIndex;
var myLabelHeight = myLabelHeightField.editValue;
var myLabelOffset = myLabelOffsetField.editValue;
var myLabelStyle = myStyleNames[myLabelStyleDropdown.selectedIndex];
var myLayerName = myLayerNames[myLayerDropdown.selectedIndex];
// Edit: added makeNewDocument
var makeNewDocument = !myExistingDocumentGroup.checkedState;
var makeNewPages = myMakeNewPagesCheckbox.checkedState;
var myAlignment = myAlignments[myAlignDropdown.selectedIndex];
myDialog.destroy();
// Edit: added makeNewDocument, makeNewPages, myAlignment
myMakeImageCatalog(myFiles, myNumberOfRows, myNumberOfColumns, myRemoveEmptyFrames, myFitProportional, myFitCenterContent, myFitFrameToContent, myHorizontalOffset, myVerticalOffset, myMakeLabels, myLabelType, myLabelHeight, myLabelOffset, myLabelStyle, myLayerName, makeNewDocument, makeNewPages, myAlignment);
} else {
myDialog.destroy();
}
}
}
function myGetParagraphStyleNames(myDocument) {
var myStyleNames = new Array;
var myAddLabelStyle = true;
for (var myCounter = 0; myCounter < myDocument.paragraphStyles.length; myCounter++) {
myStyleNames.push(myDocument.paragraphStyles.item(myCounter).name);
if (myDocument.paragraphStyles.item(myCounter).name == "Labels") {
myAddLabelStyle = false;
}
}
if (myAddLabelStyle == true) {
myStyleNames.push("Labels");
}
return myStyleNames;
}
// Edit: added makeNewDocument
function myMakeImageCatalog(myFiles, myNumberOfRows, myNumberOfColumns, myRemoveEmptyFrames, myFitProportional, myFitCenterContent, myFitFrameToContent, myHorizontalOffset, myVerticalOffset, myMakeLabels, myLabelType, myLabelHeight, myLabelOffset, myLabelStyle, myLayerName, makeNewDocument, makeNewPages, myAlignment) {
// Edit: Added myDocument
var myPage, myFile, myCounter, myX1, myY1, myX2, myY2, myRectangle, myLabelStyle, myLabelLayer, myDocument;
var myParagraphStyle, myError;
var myFramesPerPage = myNumberOfRows * myNumberOfColumns;
// Edit: new doc or not
if (makeNewDocument === true) {
myDocument = app.documents.add();
} else {
myDocument = app.activeDocument;
}
// Edit: add new layer for images
var myNewLayer = myDocument.layers.add({ name: 'layer ' + (myDocument.layers.length + 1) });
//Edit: Create page offset
var myPageOffset = 0;
var myFrameOffset = 0;
if (makeNewDocument === true) {
myPageOffset = 0;
}
// If we use the existing document and we add new pages
if (makeNewDocument === false && makeNewPages === true) {
myPageOffset = myDocument.pages.length;
myFrameOffset = myDocument.rectangles.length;
}
// If we use the existing document and we add to existing pages
if (makeNewDocument === false && makeNewPages === false){
myPageOffset = 0;
myFrameOffset = 0;
}
myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points;
myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points;
var myDocumentPreferences = myDocument.documentPreferences;
var myNumberOfFrames = myFiles.length;
var myNumberOfPages = Math.round(myNumberOfFrames / myFramesPerPage);
if ((myNumberOfPages * myFramesPerPage) < myNumberOfFrames) {
myNumberOfPages++;
}
// Edit: add number of page if not new doc
if (makeNewDocument === false && makeNewPages === true) {
myNumberOfPages = myNumberOfPages + myDocument.pages.length;
}
//If myMakeLabels is true, then add the label style and layer if they do not already exist.
if (myMakeLabels == true) {
try {
myLabelLayer = myDocument.layers.item(myLayerName);
//if the layer does not exist, trying to get the layer name will cause an error.
myLabelLayer.name;
} catch (myError) {
myLabelLayer = myDocument.layers.add({ name: myLayerName });
}
//If the paragraph style does not exist, create it.
try {
myParagraphStyle = myDocument.paragraphStyles.item(myLabelStyle);
myParagraphStyle.name;
} catch (myError) {
myDocument.paragraphStyles.add({ name: myLabelStyle });
}
}
// Edit: if the document length is shorter than the new size
if(myDocument.pages.length <= myNumberOfPages) {
myDocumentPreferences.pagesPerDocument = myNumberOfPages;
}
myDocumentPreferences.facingPages = false;
// Edit: if new doc or not
if (makeNewDocument === false) {
myPage = myDocument.pages.item(0);
} else {
myPage = myDocument.pages.item(myDocument.pages.length - 1);
}
var myMarginPreferences = myPage.marginPreferences;
var myLeftMargin = myMarginPreferences.left;
var myTopMargin = myMarginPreferences.top;
var myRightMargin = myMarginPreferences.right;
var myBottomMargin = myMarginPreferences.bottom;
var myLiveWidth = (myDocumentPreferences.pageWidth - (myLeftMargin + myRightMargin)) + myHorizontalOffset;
var myLiveHeight = myDocumentPreferences.pageHeight - (myTopMargin + myBottomMargin);
var myColumnWidth = myLiveWidth / myNumberOfColumns;
var myFrameWidth = myColumnWidth - myHorizontalOffset;
var myRowHeight = (myLiveHeight / myNumberOfRows);
var myFrameHeight = myRowHeight - myVerticalOffset;
var myPages = myDocument.pages;
// Construct the frames in reverse order. Don't laugh--this will
// save us time later (when we place the graphics).
// Edit: stops at page offset
for (myCounter = myDocument.pages.length - 1; myCounter >= myPageOffset; myCounter--) {
var myPage = myPages.item(myCounter);
for (var myRowCounter = myNumberOfRows; myRowCounter >= 1; myRowCounter--) {
myY1 = myTopMargin + (myRowHeight * (myRowCounter - 1));
myY2 = myY1 + myFrameHeight;
for (var myColumnCounter = myNumberOfColumns; myColumnCounter >= 1; myColumnCounter--) {
myX1 = myLeftMargin + (myColumnWidth * (myColumnCounter - 1));
myX2 = myX1 + myFrameWidth;
myRectangle = myPage.rectangles.add(
// Edit: add to new layer
myNewLayer,
undefined,
undefined,
{
geometricBounds: [myY1, myX1, myY2, myX2],
strokeWeight: 0,
strokeColor: myDocument.swatches.item("None")
}
);
}
}
}
// Because we constructed the frames in reverse order, rectangle 1
// is the first rectangle on page 1, so we can simply iterate through
// the rectangles, placing a file in each one in turn. myFiles = myFolder.Files;
// Edit: added separate counter for files
var myFileCounter = 0;
for (myCounter = 0; myCounter < myDocument.rectangles.length; myCounter++) {
// Edit: if the counter does not exceed the file array length
if (myFileCounter <= myFiles.length -1) {
// Edit: added [1] to account for the change from an object to an array
myFile = myFiles[myFileCounter][1];
//Edit: changed page item selection
myRectangle = myDocument.rectangles.item(myCounter + myFrameOffset);
// Edit: check if the frame is empty
if (myRectangle.contentType === ContentType.unassigned) {
myRectangle.place(File(myFile));
myRectangle.label = myFile.fsName.toString();
//Apply fitting options as specified.
if (myFitProportional) {
myRectangle.fit(FitOptions.proportionally);
}
if (myFitCenterContent) {
myRectangle.fit(FitOptions.centerContent);
}
if (myFitFrameToContent) {
myRectangle.fit(FitOptions.frameToContent);
}
//Add the label, if necessary.
if (myMakeLabels == true) {
myAddLabel(myRectangle, myLabelType, myLabelHeight, myLabelOffset, myLabelStyle, myLayerName);
}
myFileCounter ++;
}
}
}
// Edit: added alignment options
/*
for (myCounter = 0; myCounter <= myPages.length - 1; myCounter++) {
myPage = myPages.item(myCounter);
if (myAlignment === "Top") {
myDocument.align(myPage.pageItems, AlignOptions.TOP_EDGES, AlignDistributeBounds.MARGIN_BOUNDS);
}
else if (myAlignment === "Left") {
myDocument.align(myPage.pageItems, AlignOptions.LEFT_EDGES, AlignDistributeBounds.MARGIN_BOUNDS);
}
else if (myAlignment === "Right") {
myDocument.align(myPage.pageItems, AlignOptions.RIGHT_EDGES, AlignDistributeBounds.MARGIN_BOUNDS);
}
else if (myAlignment === "Bottom") {
myDocument.align(myPage.pageItems, AlignOptions.BOTTOM_EDGES, AlignDistributeBounds.MARGIN_BOUNDS);
}
}*/
for (myCounter = 0; myCounter <= myNewLayer.pageItems.length - 1; myCounter++) {
myItem = myNewLayer.pageItems[myCounter];
if (myAlignment === "Top") {
myDocument.align(myItem, AlignOptions.TOP_EDGES, AlignDistributeBounds.MARGIN_BOUNDS);
}
else if (myAlignment === "Left") {
myDocument.align(myItem, AlignOptions.LEFT_EDGES, AlignDistributeBounds.MARGIN_BOUNDS);
}
else if (myAlignment === "Right") {
myDocument.align(myItem, AlignOptions.RIGHT_EDGES, AlignDistributeBounds.MARGIN_BOUNDS);
}
else if (myAlignment === "Bottom") {
myDocument.align(myItem, AlignOptions.BOTTOM_EDGES, AlignDistributeBounds.MARGIN_BOUNDS);
}
}
if (myRemoveEmptyFrames == 1) {
for (var myCounter = myDocument.rectangles.length - 1; myCounter >= 0; myCounter--) {
if (myDocument.rectangles.item(myCounter).contentType == ContentType.unassigned) {
myDocument.rectangles.item(myCounter).remove();
} else {
//As soon as you encounter a rectangle with content, exit the loop.
break;
}
}
}
}
//Function that adds the label.
function myAddLabel(myFrame, myLabelType, myLabelHeight, myLabelOffset, myLabelStyleName, myLayerName) {
var myDocument = app.documents.item(0);
var myLabel;
var myLabelStyle = myDocument.paragraphStyles.item(myLabelStyleName);
var myLabelLayer = myDocument.layers.item(myLayerName);
var myLink = myFrame.graphics.item(0).itemLink;
//Label type defines the text that goes in the label.
switch (myLabelType) {
//File name
case 0:
myLabel = myLink.name;
break;
//File path
case 1:
myLabel = myLink.filePath;
break;
//XMP description
case 2:
try {
myLabel = myLink.linkXmp.description;
if (myLabel.replace(/^\s*$/gi, "") == "") {
throw myError;
}
} catch (myError) {
myLabel = "No description available.";
}
break;
//XMP author
case 3:
try {
myLabel = myLink.linkXmp.author;
if (myLabel.replace(/^\s*$/gi, "") == "") {
throw myError;
}
} catch (myError) {
myLabel = "No author available.";
}
break;
}
var myX1 = myFrame.geometricBounds[1];
var myY1 = myFrame.geometricBounds[2] + myLabelOffset;
var myX2 = myFrame.geometricBounds[3];
var myY2 = myY1 + myLabelHeight;
var myTextFrame = myFrame.parent.textFrames.add(myLabelLayer, undefined, undefined, {
geometricBounds: [myY1, myX1, myY2, myX2],
contents: myLabel
});
myTextFrame.textFramePreferences.firstBaselineOffset = FirstBaseline.leadingOffset;
myTextFrame.parentStory.texts.item(0).appliedParagraphStyle = myLabelStyle;
}