forked from graysitory/Novelty
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Optical_Margin_Batch.jsx
executable file
·132 lines (121 loc) · 3.13 KB
/
Optical_Margin_Batch.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
//Optical_Margin_Batch.jsx
//Indesign CS4 javascript
//Bruno Herfst 2011
//Todo:
//Ignore master pages tickbox
//test locked layers and items
//add search for style?
//calculate auto?
#target indesign;
main();
//global variables
var myDoc,mySelection,mySizeSelect,myCustomSize;
function main(){
if(app.documents.length != 0){
myDoc = app.activeDocument;
if(app.selection.length != 0){
//Get the first item in the selection.
mySelection = app.selection;
//Process the selection.
switch(mySelection[0].constructor.name){
case "Text":
case "InsertionPoint":
case "Character":
case "Word":
case "Line":
case "TextStyleRange":
case "Paragraph":
case "TextColumn":
case "TextFrame":
myDisplayDialog(true);
break;
default:
myDisplayDialog(false);
}
}else{
myDisplayDialog(false);
}
}else{
alert("Please open a document and try again.");
}
}
//Display a dialog box.
function myDisplayDialog(mySelectedBool){
var myDialog,myStoryRadio,mySizeRadio;
with(myDialog = app.dialogs.add({name:"Optical Margin Alignment"})){
with(dialogColumns.add()){
with(borderPanels.add()){
if(mySelectedBool == true){
with(myStoryRadio = radiobuttonGroups.add()){
radiobuttonControls.add({staticLabel:"All stories"});
radiobuttonControls.add({staticLabel:"Selected story", checkedState:true});
}
} else {
with(myStoryRadio = radiobuttonGroups.add()){
radiobuttonControls.add({staticLabel:"All text frames", checkedState:true});
}
}
}
with(borderPanels.add()){
with(mySizeRadio = radiobuttonGroups.add()){
radiobuttonControls.add({staticLabel:"Manual"});
radiobuttonControls.add({staticLabel:"Auto", checkedState:true});
}
with(dialogColumns.add()){
myCustomSizeBut = measurementEditboxes.add({editContents:"0"});
}
}
}
}
var myResult = myDialog.show();
if(myResult == true){
var myStorySelect = myStoryRadio.selectedButton;
mySizeSelect = mySizeRadio.selectedButton;
myCustomSize = myCustomSizeBut.editContents;
myDialog.destroy();
if(myStorySelect == 1){
doSelection(mySelection);
}else{
doAllFrames(myDoc);
}
}else{
myDialog.destroy();
}
}
function doAllFrames(myDoc){
//Get all stories in doc
for(var i=0; i<myDoc.stories.length; i++){
myStory = myDoc.stories.item(i);
doThisStory(myStory);
}
alert("Done!");
}
function doSelection(mySelection){
//If text or a text frame is selected, get the first frame of the story;
//otherwise, do nothing.
for(var i=0; i<mySelection.length; i++){
//get ref to story
switch(mySelection[i].constructor.name){
case "Text":
case "InsertionPoint":
case "Character":
case "Word":
case "Line":
case "TextStyleRange":
case "Paragraph":
case "TextColumn":
case "TextFrame":
myStory = mySelection[i].parentStory;
doThisStory(myStory);
break;
}
}
alert("Done!");
}
function doThisStory(myStory){
if(myStory.storyPreferences.opticalMarginAlignment == false){
myStory.storyPreferences.opticalMarginAlignment = true;
} else if (mySizeSelect==0){
myStory.storyPreferences.opticalMarginSize = myCustomSize;
}
}