-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup.jsx
124 lines (103 loc) · 3.83 KB
/
cleanup.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
app.scriptPreferences.version = 8; //Indesign CS6 and later. Use 7.5 to use CS5.5 features
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL; //INTERACT_WITH_ALL is the default anyway. just in case you want to change that.
app.scriptPreferences.enableRedraw = true;
var myDocument;
myDocument = app.documents.item(0);
//delete the layer
var helperLayer = returnLayerOrCreatenew("SourceLinkPageDiff");
helperLayer.remove();
//delete the object styles
var helperObjectStyle = returnObjectStyleOrCreatenew("SourceLinkPageDiffStyle");
helperObjectStyle.remove();
var helperTextframeObjectStyle = returnObjectStyleOrCreatenew("LinkPageDiffText");
helperTextframeObjectStyle.remove();
//delete the text styles
var helperTextframeParagraphStyle = returnParagraphStyleOrCreatenew("LinkPageDiff");
helperTextframeParagraphStyle.remove();
//delete colors
var color0 = returnColorOrCreateNew("DIFF-0", [60,0,100,0]);
var color1 = returnColorOrCreateNew("DIFF-1", [60,0,30,0]);
var color10 = returnColorOrCreateNew("DIFF-10", [0,45,100,0]);
var colorMore = returnColorOrCreateNew("DIFF-MORE", [0,100,100,0]);
var colorWeiss = returnColorOrCreateNew("DIFF-WEISS", [0,0,0,0]);
myDocument.swatches.item(color0.name).remove();
myDocument.swatches.item(color1.name).remove();
myDocument.swatches.item(color10.name).remove();
myDocument.swatches.item(colorMore.name).remove();
myDocument.swatches.item(colorWeiss.name).remove();
//Functions
function returnColorOrCreateNew(colorName, cmykValues){
var color;
color = myDocument.colors.item(colorName);
try{
name = color.name;
} catch (e) {
color = myDocument.colors.add({
name: colorName,
model: ColorModel.PROCESS,
space: ColorSpace.CMYK,
colorValue: cmykValues
});
}
return color;
}
function returnLayerOrCreatenew(layerName){
var layer;
layer = myDocument.layers.item(layerName);
try{
name = layer.name;
} catch(e) {
layer = myDocument.layers.add({name: layerName});
}
return layer;
}
//return an existing object style or create a new object style. if preferences are given, these will be applied to the new object style only.
function returnObjectStyleOrCreatenew(objectStyleName, newObjectStylePreferences){
var objectStyle;
objectStyle = myDocument.objectStyles.item(objectStyleName);
try{
name = objectStyle.name;
} catch(e) {
if (newObjectStylePreferences != null) {
newObjectStylePreferences.name = objectStyleName;
objectStyle = myDocument.objectStyles.add(newObjectStylePreferences);
} else {
objectStyle = myDocument.objectStyles.add({name: objectStyleName});
}
}
return objectStyle;
}
//return the reference to a paragraph style. if the style did not exist, create the style
function returnParagraphStyleOrCreatenew(stylename, groupname, stylePreferences){
var style;
var group;
//prepare style preferences. if none are given, only include the name
if (stylePreferences == null){
stylePreferences = {name: stylename};
} else {
stylePreferences.name = stylename;
}
if (!groupname){ //is the style in a group?
style = myDocument.paragraphStyles.item(stylename);
} else {
try { //add group first, if it does not exist
group = myDocument.paragraphStyleGroups.itemByName(groupname);
gname = group.name; //will trigger error if group does not exist
}
catch(e){
group = myDocument.paragraphStyleGroups.add({name: groupname});
style = group.paragraphStyles.add(stylePreferences); //then add style in the group
}
style = group.paragraphStyles.itemByName(stylename); //select style in group (for the second time, if the style had already been created, but that should be ok)
}
try{
name=style.name; //will trigger error if style does not exist
} catch(e) {
if (group != null){
style = group.paragraphStyles.add(stylePreferences);
} else {
style = myDocument.paragraphStyles.add(stylePreferences);
}
}
return style;
}