-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateTextLabels.jsx
More file actions
105 lines (97 loc) · 3.7 KB
/
CreateTextLabels.jsx
File metadata and controls
105 lines (97 loc) · 3.7 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
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
// Resizes and repositions variable text fields to fit correctly on cheese marker vector cutting patern
// Max dimensions for text labels: 0.35in W & 1.35in H (25pt W x 97pt H)
function getLabelPosition() {
"use strict";
var offset = 243,
fullPath;
// 243 pt between labels, 97pt long text path
function calculatePosition(labelNum) {
if (labelNum > 16) {
//4th row, 5 labels
if (labelNum === 17) {
fullPath = [[219, -167.5], [219, -264.5]];
} else {
fullPath[0][0] = fullPath[0][0] + offset;
fullPath[1][0] = fullPath[1][0] + offset;
}
} else if (labelNum > 10) {
//3rd row, 6 labels
if (labelNum === 11) {
fullPath = [[70, -237], [70, -140]];
} else {
fullPath[0][0] = fullPath[0][0] + offset;
fullPath[1][0] = fullPath[1][0] + offset;
}
} else if (labelNum > 5) {
//2nd row, 5 labels
if (labelNum === 6) {
fullPath = [[219, -50.5], [219, -147.5]];
} else {
fullPath[0][0] = fullPath[0][0] + offset;
fullPath[1][0] = fullPath[1][0] + offset;
}
} else {
//1st row, 6 labels
if (labelNum === 0) {
fullPath = [[70, -120], [70, -23]];
} else {
fullPath[0][0] = fullPath[0][0] + offset;
fullPath[1][0] = fullPath[1][0] + offset;
}
}
return fullPath;
}
return calculatePosition;
}
function buildPathTextFrame(coordArray, align, textSize, fontFamily, name) {
"use strict";
var newPath,
pTextFrame;
newPath = app.activeDocument.pathItems.add();
newPath.setEntirePath(coordArray);
pTextFrame = app.activeDocument.textFrames.pathText(newPath);
pTextFrame.textRange.paragraphAttributes.justification = align;
pTextFrame.textRange.characterAttributes.size = textSize;
pTextFrame.textRange.characterAttributes.textFont = textFonts.getByName(fontFamily);
pTextFrame.name = name;
return pTextFrame;
}
function overflows(tF) {
"use strict";
var charCount = 0, i;
for (i = 0; i < tF.lines.length; i++) {
charCount += tF.lines[i].characters.length;
}
return charCount < tF.characters.length;
}
function main() {
"use strict";
var labelTextFrame,
labelMaker,
pathEndPoints,
fontSize,
i,
docRef = app.activeDocument,
labelTypeface = "Garamond",
if (docRef.variables.length === 22) {
labelMaker = getLabelPosition();
for (i = 0; i < docRef.variables.length; i++) {
//determine start/end points of line
pathEndPoints = labelMaker(i);
fontSize = 24;
labelTextFrame = buildPathTextFrame(pathEndPoints, Justification.CENTER, fontSize, labelTypeface, ("NewLabel" + i));
// set primary textFrame's contents and decrement 5% each loop until all text fit onto primary labelTextFrame
labelTextFrame.contents = docRef.variables[i].pageItems[0].contents;
while (overflows(labelTextFrame) === true) {
fontSize *= 0.95;
labelTextFrame.textRange.characterAttributes.size = Math.round(fontSize);
}
// final font resize to format text that moved back from the overflowChecker object
labelTextFrame.textRange.characterAttributes.size = Math.round(fontSize);
}
redraw();
} else {
alert("Error, script detected more than 22 label variables\nPlease confirm correct 20x4 template is open and selected in Illustrator.");
}
}
main();