forked from GitBruno/Novelty
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Frame_Break_2_Pagebounds.jsx
executable file
·142 lines (122 loc) · 3.75 KB
/
Frame_Break_2_Pagebounds.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
/*
--------------------------------------------
Break_Frame_2_Pagebounds.jsx
An InDesign CS5/6 Javascript
Version 1.1
Bruno Herfst 2013-2015
This script breaks graphic frames over pages using pathfinder commands.
--------------------------------------------
*/
#target InDesign;
//////////////
// SETTINGS //
//////////////
doTextFrames = false;
//Make certain that user interaction (display of dialogs, etc.) is turned on.
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
if (app.documents.length != 0) {
//global vars
var myCover = app.activeDocument;
var myCoverBleed = {
Top : myCover.documentPreferences.documentBleedTopOffset,
Bottom : myCover.documentPreferences.documentBleedBottomOffset,
Left : myCover.documentPreferences.documentBleedInsideOrLeftOffset,
Right : myCover.documentPreferences.documentBleedOutsideOrRightOffset
};
if(breakCover(myCover)) {
alert("Done!");
}
} else {
alert("Can’t find any open documents.");
}
function breakCover(myCover){
//For all spreads
var spreadsLen = myCover.spreads.length;
for (var i=spreadsLen-1; i>=0; i--){
breakSpread(myCover, myCover.spreads[i]);
}
return true;
}
function breakSpread(myCover, mySpread){
var ruleror = myCover.viewPreferences.rulerOrigin;
myCover.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN;
var mySpreadRectangles = mySpread.rectangles;
var mySpreadOvals = mySpread.ovals;
var mySpreadPolygons = mySpread.polygons;
var mySpreadPages = mySpread.pages;
var pagesLen = mySpreadPages.length;
var myPages = new Array();
for (var page = pagesLen-1; page>=0; page--){
// Get page bounds including bleed
if(page == 0){ // first
var myFrameBounds = getPageBounds(mySpreadPages[page],3);
} else if (page == pagesLen-1){
var myFrameBounds = getPageBounds(mySpreadPages[page],1);
} else {
var myFrameBounds = getPageBounds(mySpreadPages[page],2);
}
myPages.push({page: mySpreadPages[page], bounds:myFrameBounds});
}
if(myPages.length > 1) {
breakFramesTo(myPages,mySpreadRectangles);
breakFramesTo(myPages,mySpreadOvals);
breakFramesTo(myPages,mySpreadPolygons);
}
myCover.viewPreferences.rulerOrigin = ruleror;
return true;
}
function breakFramesTo(myPages,mySpreadItems){
for ( i = mySpreadItems.length-1; i >= 0; i-- ) {
var spreadItem = mySpreadItems[i];
var myLayer = spreadItem.itemLayer;
//make sure layer is unlocked
var myLayerLock = myLayer.locked;
if(myLayerLock){
myLayer.locked = false;
}
// Check item agains every page
var pagesLen = myPages.length;
for (var j = pagesLen-1; j >= 0; j--){
var myDupItem = spreadItem.duplicate();
var rect = myPages[j].page.rectangles.add(myLayer,{geometricBounds:myPages[j].bounds, fillColor:"None", strokeColor:"None"});
rect.sendToBack();
try {
rect.intersectPath(myDupItem);
} catch(e) {
// Don't break if it doesn't work out. It's OK.
rect.remove();
myDupItem.remove();
// alert(e.description);
}
}
spreadItem.remove();
//set original lock
if(myLayerLock){
myLayer.locked = true;
}
}
}
function getPageBounds(myPage,selector){
var myBleedBounds = myPage.bounds; //[y1, x1, y2, x2]
// Add top and bottom bleed
myBleedBounds[0] -= myCoverBleed.Top;
myBleedBounds[2] += myCoverBleed.Bottom;
// Left and right bleed
switch (selector){
case 2:
return myBleedBounds; // Return page-bounds with top+bottom bleed
break;
case 3:
myBleedBounds[1] -= myCoverBleed.Left;
return myBleedBounds;
break;
case 1:
myBleedBounds[3] += myCoverBleed.Right;
return myBleedBounds;
break;
default: // Return page-bounds without bleed
return myPage.bounds;
break;
}
}