-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathDevider Guide.jsx
165 lines (150 loc) · 4.88 KB
/
Devider Guide.jsx
1
// PS Devider Guide// Bruno Herfst 2010//// A photoshop javascript for making guides by deviding file demensions.// Works niceley with bookcovers too.// tested in Photoshop CS4app.bringToFront();buildDialog();// Create the dialog windowfunction buildDialog(){ // The dialog window var dlg = new Window("dialog", "Devider Guide"); // The input fields with labels var uD = undefined; dlg.heightLabel = dlg.add("statictext", uD, "Horizontal Devide"); dlg.heightInput = dlg.add("edittext", [15,35,110,55]); dlg.widthLabel = dlg.add("statictext", uD, "Vertical Devide"); dlg.widthInput = dlg.add("edittext", [15,35,110,55]); dlg.mmcheckbox = dlg.add('checkbox', [15,35,110,55], 'mm i.s.o px'); dlg.bleedcheckbox = dlg.add('checkbox', [15,35,110,55], 'Incl bleed'); dlg.bleedLabel = dlg.add("statictext", uD, "Bleed"); dlg.bleedInput = dlg.add("edittext", [15,35,110,55]); dlg.spinecheckbox = dlg.add('checkbox', [15,35,110,55], 'Cover'); dlg.spineLabel = dlg.add("statictext", uD, "Spine Width"); dlg.spineInput = dlg.add("edittext", [15,35,110,55]); dlg.cancelBut = dlg.add("button", uD, "Cancel"); dlg.buildBut = dlg.add("button", uD, "OK"); // The buttons dlg.cancelBut.onClick = function () { dlg.close(); } dlg.buildBut.onClick = function () { dlg.close(); checkInput(dlg); } // Go and get the variables! dlg.show();}function checkInput(dlg){ // Let’s define the variables var goAhead = 0; var HrznDevide = Number(dlg.heightInput.text); var VrtcDevide = Number(dlg.widthInput.text); var myBleed = Number(dlg.bleedInput.text); var myBleedBool = dlg.bleedcheckbox.value; var mySpine = Number(dlg.spineInput.text); var mySpineBool = dlg.spinecheckbox.value; var myMMBool = dlg.mmcheckbox.value; var allValues = new Array(HrznDevide, VrtcDevide); if(myBleedBool==true){ allValues.push(myBleed); if(mySpineBool==true){ allValues.push(mySpine); } } for(var myCounter = 0; myCounter < allValues.length; myCounter++){ var thisValue = allValues[myCounter]; if (isNaN(thisValue)){ alert("use numbers please"); buildDialog(); goAhead = 1; break; } } if (goAhead == 0){ go(HrznDevide, VrtcDevide, myBleed, myBleedBool, myMMBool, mySpine, mySpineBool); }}function go(HrznDevide, VrtcDevide, myBleed, myBleedBool, myMMBool, mySpine, mySpineBool){ // Lets save the original unit and talk pixels from now on var originalUnit = preferences.rulerUnits; preferences.rulerUnits = Units.PIXELS; var myRes = Number(app.activeDocument.resolution); var myWidth = Number(app.activeDocument.width); var myHeight = Number(app.activeDocument.height); if(myBleedBool==true){ if(myMMBool==true){ var bleedPx = convertToPixels(myBleed); } else { var bleedPx = myBleed; } if(bleedPx >= (myWidth/2) || bleedPx >= (myHeight/2)){ alert("Bleed was bigger then document and therefore set to zero") bleedPx=0; } } if(mySpineBool==true){ if(myMMBool==true){ mySpine = convertToPixels(mySpine); } if(mySpine >= (myWidth-(bleedPx*2))){ alert("Spine is bigger then document and therefore set to zero") mySpine=0; } } var actualHeight = myHeight-(bleedPx*2); if(mySpineBool == true){ var actualWidth = (myWidth-mySpine-(bleedPx*2))/2; } else { var actualWidth = myWidth-(bleedPx*2); } //Horzontal Guides var VrtcPart = actualHeight/VrtcDevide; var VrtcOffset = bleedPx; for(var myCounter = -1; myCounter < VrtcDevide; myCounter++){ makeGuide(VrtcOffset,"Hrzn"); VrtcOffset += VrtcPart; } //Vertical Guides var HrznPart = actualWidth/HrznDevide; var HrznOffset = bleedPx; if(mySpineBool == true){ //Lets make guides for the spine first for(var myCounter = -1; myCounter < HrznDevide; myCounter++){ makeGuide(HrznOffset,"Vrtc"); makeGuide(HrznOffset + actualWidth + mySpine,"Vrtc"); HrznOffset += HrznPart; } } else { for(var myCounter = -1; myCounter < HrznDevide; myCounter++){ makeGuide(HrznOffset,"Vrtc"); HrznOffset += HrznPart; } } // restore original ruler preferences.rulerUnits = originalUnit; /* makeGuide function originally found at: http://blogs.adobe.com/crawlspace/2006/05/installing_and_1.html */ function makeGuide(pixelOffSet, orientation) { var id8 = charIDToTypeID( "Mk " ); var desc4 = new ActionDescriptor(); var id9 = charIDToTypeID( "Nw " ); var desc5 = new ActionDescriptor(); var id10 = charIDToTypeID( "Pstn" ); var id11 = charIDToTypeID( "#Pxl" ); // units -> original value #Rlt desc5.putUnitDouble( id10, id11, pixelOffSet ); // integer var id12 = charIDToTypeID( "Ornt" ); var id13 = charIDToTypeID( "Ornt" ); var id14 = charIDToTypeID( orientation ); // "Vrtc", "Hrzn" desc5.putEnumerated( id12, id13, id14 ); var id15 = charIDToTypeID( "Gd " ); desc4.putObject( id9, id15, desc5 ); executeAction( id8, desc4, DialogModes.NO ); } //convert mm to inch, then gets multipliued by PPI to get pixels. function convertToPixels(mm){ return (mm/25.4)*myRes; } }