/***********************************************************************/
/* */
/* CleanupPasteboard :: Remove external page items */
/* from the whole document */
/* */
/* [Ver: 1.12] [Author: Marc Autret] [Modif: 03/14/17] */
/* [Lang: EN|FR] [Req: InDesign CS4/CS5/CS6/CC] [Creat: 09/03/09] */
/* */
/* Installation: */
/* */
/* 1) Place the current file into Scripts/Scripts Panel/ */
/* */
/* 2) Run InDesign, open a document */
/* */
/* 3) Exec script from Window > Automatisation > Scripts */
/* (double-click on the script name) */
/* */
/* Bugs & Feedback : marc{at}indiscripts{dot}com */
/* www.indiscripts.com */
/* */
/***********************************************************************/
var SCRIPT = {
name: 'CleanUpPasteboard',
version: '1.12'
};
//======================================
// :: FRENCH_LOCALE
//======================================
// Remove objects outside: :: Supprimer les objets au-del\u00E0 de :
// Bleed :: Fonds perdus
// Slug :: Ligne-bloc
// Custom page offset: :: Distance de la page :
// Parse master spreads :: Inclure les gabarits
// Preserve threaded text frames :: Pr\u00E9server les blocs cha\u00EEn\u00E9s
// Items removed: :: Objets supprim\u00E9s :
//
var L10N = L10N || (function()
{
var __com = '// ', __sep = ' :: ', __beg = '', __end = '';
var ln = (function()
{ // : Number
for(var p in Locale) if(Locale[p] == this) return(p);
}).call(app.locale);
var parseL10N = /*str[]*/function(/*str*/locale_)
{ // : File
var line, lines=[], r=[];
var uEsc = function(){return String.fromCharCode(Number('0x'+arguments[1]));}
if( this.open('r') )
{
var comSize=__com.length;
while( !this.eof )
{
line = this.readln().replace(/\\u([0-9a-f]{4})/gi, uEsc);
if( line.indexOf(__com) != 0 ) continue;
if( line.indexOf(__end) >= 0 ) break;
if( line.indexOf(__sep) < 0 ) continue;
lines.push(line.substr(comSize).split(__sep));
}
this.close();
}
var locIndex = (function()
{ // : Attay
while( (line=this.shift()) && line[0] != __beg ) {};
if (!line) return false;
for (var i=1,sz=line.length ; iBleed | 1=>Slug | 2=>Custom
// customOffset (num) : a measurementEditbox value (in pts)
// parseMaster (bool) : parse masterSpreads flag
{
var dlg = this.dialogs.add( {name: ' '+SCRIPT.name+' '+SCRIPT.version, canCancel: true} );
var PREF_UNITS = MeasurementUnits.MILLIMETERS;
var rgOffsets, meOffset, cbMaster;
with ( dlg )
{
with ( dialogColumns.add().borderPanels.add().dialogColumns.add() )
{
staticTexts.add( {staticLabel:__("Objekte löschen, ausserhalb: ")} );
with ( (rgOffsets=radiobuttonGroups.add()).radiobuttonControls )
{
add( {staticLabel: __("Anschnitt")} );
add( {staticLabel: __("Infobereich") } );
add( {staticLabel: __("Abstand zur Seite größer: "), checkedState: true} );
}
meOffset = measurementEditboxes.add( {editUnits: PREF_UNITS, editValue: 0, smallNudge: 1 });
cbMaster = checkboxControls.add( {staticLabel:__("Musterseiten einbeziehen")} );
cbKeepThreaded = checkboxControls.add( {staticLabel:__("Textverkettungen nicht auflösen"), checkedState: true} );
}
}
var r = ( dlg.show() ) ?
{
choice: rgOffsets.selectedButton,
customOffset: meOffset.editValue,
parseMaster: cbMaster.checkedState,
keepThreaded: cbKeepThreaded.checkedState,
} : false;
dlg.destroy();
return(r);
}
DocumentPreference.prototype.bsOffsets = function(/*[0=Bleed|1=Slug]*/bsOption)
// Return bleed/slug offsets in the [top,left,bottom,right] form
// The top/bot values are Numbers returned in the current vertical measurement units
// The left/right values are Numbers returned in the current horizontal measurement units
{
var bs = (bsOption)?'slug':'documentBleed';
var right = (bsOption)?'RightOrOutsideOffset':'OutsideOrRightOffset';
return [ this[bs+'TopOffset'], this[bs+'InsideOrLeftOffset'],
this[bs+'BottomOffset'], this[bs+right] ];
}
ViewPreference.prototype.toOffsets = function(/*num*/ptsValue)
// Convert to the appropriate h-units and v-units values
// according to the current measurement units
// Return an array in the form [top,left,bottom,right]
{
var uv = UnitValue(ptsValue, 'pt');
var h = uv.as(UNITS[this.horizontalMeasurementUnits]);
var v = uv.as(UNITS[this.verticalMeasurementUnits]);
return [v,h,v,h];
}
Document.prototype.cleanOut = function(/*arr*/offsets, /*bool*/parseMaster, /*bool*/keepThreaded)
// Remove "out of bounds" items
// : a [top,left,bot,right] array of numbers to offset each spread bounds
// : if true, parse also the master spreads
// The top/bot values are given in the current vertical measurement units
// The left/right values are given in the current horizontal measurement units
{
var outOf = function(b)
{ // context: pageItem bounds
return this[2]b[2] || this[1]>b[3];
}
var extraBounds = function()
{ // context: Spread or MasterSpread
var bFirst = this.pages.item(0).bounds; // bounds of the first page
var bLast = this.pages.item(-1).bounds; // bounds of the last page
return [ bFirst[0]-offsets[0], bFirst[1]-offsets[1],
bLast[2]+offsets[2], bLast[3]+offsets[3] ];
};
var spreads = this.spreads.everyItem().getElements();
if (parseMaster)
spreads = spreads.concat(this.masterSpreads.everyItem().getElements());
var cpt=0;
var i, s, iBounds, eBounds, items;
// [fix091203]
var ro = this.viewPreferences.rulerOrigin;
this.viewPreferences.rulerOrigin = RulerOrigin.spreadOrigin;
// [/fix091203]
while(s=spreads.pop()) // for each spread
{
eBounds = extraBounds.call(s); // get extra bounds
items = s.pageItems.everyItem().getElements();
while(i=items.pop()) // for each item
{
// [ADD170314]
if( keepThreaded && (i instanceof TextFrame) && 1 < i.parentStory.textContainers.length ) continue;
// [/ADD170314]
if ( outOf.call(i.visibleBounds,eBounds) )
try {i.remove();cpt++} catch(ex){};
}
}
this.viewPreferences.rulerOrigin = ro; // [fix091203]
return(cpt);
}
// Main process
Application.prototype.main = function() {
if (! this.documents.length ) return;
// run the dialog
var ui = app.showUI();
if (! ui ) return;
// create the array of [top,left,bot,right] offsets
var doc = this.activeDocument;
var offsets = ( ui.choice > 1 ) ?
doc.viewPreferences.toOffsets(ui.customOffset) :
doc.documentPreferences.bsOffsets(ui.choice);
// cleanup
alert(__("Anzahl Objekte entfernt: ") + ' ' + doc.cleanOut(offsets, ui.parseMaster, ui.keepThreaded));
}
function myGetScriptPath() {
try{
return app.activeScript;
}
catch(myError){
return File(myError.fileName);
}
}
//app.main();
app.doScript('app.main();', ScriptLanguage.javascript, undefined, UndoModes.entireScript, SCRIPT.name);