forked from graysitory/Novelty
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Spine-Gutter_Corrector.jsx
executable file
·176 lines (159 loc) · 5.77 KB
/
Spine-Gutter_Corrector.jsx
1
////////////////////////////////////////////////// D E P R E C I A T E D////////////////////////////////////////////////// Get the latest version here:// http://coverbuilder.brunoherfst.com//////////////////////////////////////////////////Spine Corrector//Bruno Herfst 2010#target indesign;if(app.documents.length != 0){ // get a ref to active doc var myDoc = app.activeDocument; //Get a reference to the first page var myPage = myDoc.pages.item(0); //Check if the page is set up the right way if (myDoc.documentPreferences.facingPages == false){ if (myPage.marginPreferences.columnCount == 2){ //User defined variable var newSpine = prompt ("Enter the new spinewidth", "", "New Spine Width"); } else { alert("Couldn’t find the spine (=column gutter)"); exit(); } } else { alert ("Set facing pages Off before running this script"); exit(); }}else { alert("No documents are open. Please open a document and try again."); exit();}if ( isNaN (newSpine)){ alert("Fill in a number next time"); exit();}//Set the measurement units and ruler originmyDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.millimeters;myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.millimeters;myDoc.viewPreferences.rulerOrigin = RulerOrigin.spreadOrigin;//get the current pagewidthvar myPageW = myDoc.documentPreferences.pageWidth;//get old spine from guttervar oldSpine = myPage.marginPreferences.columnGutter;// calculate books widthvar coverW = (myPageW-oldSpine)/2;//find out the differencevar difference = newSpine-oldSpine;//------------------------------------// Mind you that indesign now already moves all the objects in the slug/bleed area out!myDoc.documentPreferences.pageWidth = myPageW+difference;//and set the new gutter on every pagefor (var myCounter = 0; myCounter < myDoc.pages.everyItem().getElements().length; myCounter++){ myDoc.pages.item(myCounter).marginPreferences.columnGutter = newSpine; myDoc.pages.item(myCounter).marginPreferences.columnCount = 2;}//and masterspreadfor (var myCounter = 0; myCounter < myDoc.masterSpreads.everyItem().getElements().length; myCounter++){ myMasterSpread = myDoc.masterSpreads.item(myCounter); for (var i = 0; i < myMasterSpread.pages.everyItem().getElements().length; i++){ myMasterPage=myMasterSpread.pages.item(i); myMasterPage.marginPreferences.columnGutter = newSpine; myMasterPage.marginPreferences.columnCount = 2; }}//Let’s get every itemfor (var myCounter = 0; myCounter < myDoc.spreads.everyItem().getElements().length; myCounter++){ mySpread = myDoc.spreads.item(myCounter); // I like to move it move it move it! adjustSpread(mySpread, difference/2);}//Let’s get every item on masterspreads too!for (var myCounter = 0; myCounter < myDoc.masterSpreads.everyItem().getElements().length; myCounter++){ myMasterSpread = myDoc.masterSpreads.item(myCounter); // I like to move it move it move it! adjustSpread(myMasterSpread, difference/2);}function adjustSpread(mySpread, myX){ var mySpreadItem; var myResetItemLock = false; var myResetLayerLock = false; for(var myCounter = 0; myCounter < mySpread.pageItems.length; myCounter ++){ mySpreadItem = mySpread.pageItems.item(myCounter); //let’s see where we are… var myGeometricBounds = mySpreadItem.geometricBounds var myX1 = myGeometricBounds[1]; var myX2 = myGeometricBounds[3]; if(mySpreadItem.locked == true){ mySpreadItem.locked = false; myResetItemLock = true; } if(mySpreadItem.itemLayer.locked == true){ mySpreadItem.itemLayer.locked = false; myResetLayerLock = true; } // We don’t need to move items in the spine/bleed when the cover gets wider because indesign allready moved this for us if (newSpine > oldSpine){ if (myX2 > 0 && myX1 < myPageW+difference){ move(mySpreadItem, myX, myX1, myX2); } } else { move(mySpreadItem, myX, myX1, myX2); } if(myResetItemLock == true){ mySpreadItem.locked = true; } if(myResetLayerLock == true){ mySpreadItem.itemLayer.locked = true; } }}function move(mySpreadItem, myX, myX1, myX2){ // Move cover 1. //met 0.25mm speling if (myX1 >= coverW+oldSpine+(difference/2)-0.25){ mySpreadItem.move(undefined, [myX, 0]); // Move cover 4 but not the spine. //met 0.25mm speling } else if (myX1 <= coverW+(difference/2)+0.25 && myX2 <= coverW+(difference/2)+0.25){ mySpreadItem.move(undefined, [0-myX, 0]); }}//The default horizontal and vertical values for indesignvar horizontal = 1752134266;var vertical = 1986359924;for (var myCounter = 0; myCounter < myDoc.guides.everyItem().getElements().length; myCounter++){ myGuide = myDoc.guides.item(myCounter); // we only need to move the verticals if (myGuide.orientation == vertical){ myResetItemLock = false; myResetLayerLock = false; if(myGuide.locked == true){ myGuide.locked = false; myResetItemLock = true; } if(myGuide.itemLayer.locked == true){ myGuide.itemLayer.locked = false; myResetLayerLock = true; } if (newSpine > oldSpine){ // We don’t need to move items in the spine/bleed when the cover gets wider because indesign allready moved this for us if (myGuide.location > 0 && myGuide.location < myPageW+difference){ if (myGuide.location >= coverW+oldSpine+(difference/2)){ myGuide.location = myGuide.location+(difference/2); } else if (myGuide.location <= coverW+(difference/2)){ myGuide.location = myGuide.location-(difference/2); } } } else { if (myGuide.location >= coverW+oldSpine+(difference/2)){ myGuide.location = myGuide.location+(difference/2); } else if (myGuide.location <= coverW+(difference/2)){ myGuide.location = myGuide.location-(difference/2); } } if(myResetItemLock == true){ myGuide.locked = true; } if(myResetLayerLock == true){ myGuide.itemLayer.locked = true; } }}