Skip to main content
Known Participant
May 1, 2016
Question

Guides and cropping

  • May 1, 2016
  • 15 replies
  • 4551 views

Hi,

I have CS6, the extendscript tool, and am thinking of Photoshop.  Of course, guides snap to the edges of my images. If I place 4 guides around my photo, and drag the crop tool; it will snap to each of these guides.  Is it possible to write a script to: First, automatically place 3 guides on my image: one on the top edge, one of the right side, and one on the bottom edge?  (then the script would have to pause or end, while I  manually place the last on the left side.)  And, then, if the positions of these guides are "known" to Photoshop; can a script place the crop tool on the rectangle defined by these 4 guides?

I can create an action that does the first part: that places 3 guides, automatically on the edges.  Once I place the 4th guide, the crop tool will automatically size itself to fit right on the rectangles outlined by the guide.  But I have to do a lot of zooming and panning to place the 4th guide, to get it just right.  I notice, however, that if I click with the magnetic lasso tool--in the general vicinity of where the 4th guide needs to go--that I can zoom in, and Photoshop keeps the zoom focused on that first click of the lasso tool.  I can escape out of it, place a guide there, then, the crop tool seems to automatically go where I want it to.

I am just wondering how aware Photoshop is of the positions of the guides, the edges of the images, and if it stores this information to variables, that in turn could be used when placing the crop tool.

Thanks, Steve

This topic has been closed for replies.

15 replies

Participant
May 23, 2018

Here is the script I wrote based on JJ's four guides script. I simplified the code a little bit and it works. I tested it on Adobe Photoshop CC2017.

The script retrieves the position of four guides and then crops the image exactly by snapping on those guides. You have to have four and only four guides in order for script to do the cropping. You can position those guides manually or you could use the popular extension for Photoshop called GuideGuide.

// Function for getting horizontal guides

function getHorizontalGuides() {

    // VARIABLES

    theGuides = []; // Array that contains only horizontal guides

    for (i = 0; i < app.activeDocument.guides.length; i++) {

        if (app.activeDocument.guides.direction == Direction.HORIZONTAL) {

            theGuides.push(app.activeDocument.guides);

        }

    }

    return theGuides;

}

// Function for getting vertical guides

function getVerticalGuides() {

    // VARIABLES

    theGuides = []; // Array that contains only vertical guides

    for (i = 0; i < app.activeDocument.guides.length; i++) {

        if (app.activeDocument.guides.direction == Direction.VERTICAL) {

            theGuides.push(app.activeDocument.guides);

        }

    }

    return theGuides;

}

// Crop the image by defined guides

function cropByGuides() {

    // VARIABLES

    var horizontalGuides = getHorizontalGuides(),

        verticalGuides = getVerticalGuides(),

        theRegion;

    // Check if the are only 4 guides and only 2 horizontal and 2 vertical guides. All conditions must be fulfilled in order for script to work

    if (app.activeDocument.guides.length === 4 && horizontalGuides.length === 2 && verticalGuides.length === 2) {

        theRegion = [verticalGuides[0].coordinate, horizontalGuides[0].coordinate, verticalGuides[1].coordinate, horizontalGuides[1].coordinate];

        app.activeDocument.crop(theRegion);

    }

}

cropByGuides();

Known Participant
May 5, 2016

JJR Mack: I got it to work. Thank you, Steve

JJMack
Community Expert
Community Expert
May 5, 2016

Good show I like it when users learn and beome able to do things. I don't like it when user want us to do it for them because they are lazy and do not want to learn a little scripting. 

JJMack
Known Participant
May 5, 2016

Thanks again.  I have posted a new question.  I am really hoping to create an interface wherein a. I can move the cursor position, using the keyboard and 2. zoom into the last click or cursor position.

Steve

Known Participant
May 4, 2016

Thanks very much.  I deselected Adobe default Bicubic Automatic and the script runs to the end.  It is still moving the guides, but I will sort it out.  It's great that your code can select the rectangle!  You code and explanation are invaluable.   Thanks again,  Steve

JJMack
Community Expert
Community Expert
May 4, 2016

Its not moving the guides it resizing the layer, moving the layer to the guides and masking the layer.

JJMack
Known Participant
May 4, 2016

and the guides have been moved

JJMack
Community Expert
Community Expert
May 4, 2016

snowy photos wrote:

and the guides have been moved

The script move no guides it fits the layer to the guides the results should look like a centered aspect ratio centered crop of the layer. Nothing is cropped the layers is just resized for the area and moved to the guides and masked to the aspect ratio.  The layer size was changed and the layer was moved.  The guide are where you set them.

This is an old script I wrote not a new script I wrote to do what you want that is for you to do. What I have posted is meant to help you to be able to do what you want. That is for you to do.

JJMack
Known Participant
May 4, 2016

I commented out the 3 lines with " app.preferences.interpolation" in them.  Ran the script. The result shows that something outside the cat has not been removed. the guides are still there, although easily removed with an action.  So I need an alternative method to app.preferences.interpolation.  Also, for some reason, the script now does not crop to the inner triangle.  So app.preferences.interpolation is important.

JJMack
Community Expert
Community Expert
May 4, 2016

Your on the perpetual version of CS6 Adobe introduced a bug in script in CS6 they have fixed it in the subscription version of CS6,

Set your Photoshop Preference for default Image Interpolation form  Adobe default Bicubic Automatic to any other setting.  Bicibic Automatic is a bad default choice to begin with and CS6 scripting can not even retrieve that setting a  general internal error is generated instead,  My script is trying to save your setting so it can set the interpolation method I want to use then restore your setting.

JJMack
Known Participant
May 4, 2016

I loaded an image; because it comes up as a background image, I copied it into a new layer, and dragged in the 4 guides.  I ran the script.  You can see that it selected the inner rectangle; but it runs into an error at line 89:

var userResampleMethod = app.preferences.interpolation; // Save interpolation settings 

This might have to do with a reported bug?  https://www.google.com/search?q=var+userResampleMethod+%3D+app.preferences.interpolation&ie=utf-8&oe=utf-8#q=%22app.pref…

I have CS6, Photoshop, 13.0.1 x64, on Windows.

Thank you,

Steve

Known Participant
May 4, 2016

Hi JJMack: Thanks.  That works beautifully.  Now I just need to add in the crop.  I think I will try will scriptlistener.  The mask in the photo above (vs. the actual image) was somehow produced when I took a screenshot, and action that photoshop somehow reacted to.

Steve

JJMack
Community Expert
Community Expert
May 4, 2016

To do the crop or clear you do not need to user scriptlistener action manager code.  To do the crop you would retrieve the four guide locations and set a selection for the rectangle area then surround.  Then if you working on a document the you only concern is the current composite view you crop.  If you working with many image layer you want to crop differently you would invert the selection and clear the layer outside the guides. The the action would clear the guide and move onto the next image layer set new guides etc.  When all Image layers were trimmed you would use export layer to file save out png-24 option trim to trim the layers transparency.

Here is a script I wrote the script retrieves the four guides the users set and sets the selection  resizes the current active layer to fill the area.  This reviled a bug the is in all version of Photoshop Resizing the a layer Photoshop messes around with the document history states and when there is and active selection back up in history. If a script had suspended history Photoshop back up to a history prior to the script execution deleting the last step the user did prior the running the script.  Results can be quite destructive the current layer your working on may longer exists.   To get around the bug I deselected before the resize then reselect. I then align the resize layer to the selection center and add the selection to the layer as a layer mask to mask off any excess that may be on two sides so the resize only fills the selection aspect ratio area.

FitImageToGuides.jsx

/* ==========================================================

// 2014  John J. McAssey (JJMack)

// ======================================================= */

// This script is supplied as is. It is provided as freeware.

// The author accepts no liability for any problems arising from its use.

/* Help Category note tag menu can be used to place script in automate menu

<javascriptresource>

<about>$$$/JavaScripts/FitImageToGuides/About=JJMack's FitImageToGuides .^r^rCopyright 2014 Mouseprints.^r^rFour and only four guides are required</about>

<category>JJMack's Script</category>

</javascriptresource>

*/

// enable double-clicking from Mac Finder or Windows Explorer

#target photoshop // this command only works in Photoshop CS2 and higher

// bring application forward for double-click events

app.bringToFront();

// ensure at least one document open

if (!documents.length) alert('There are no documents open.', 'No Document');

else {

  // declare Global variables

  //main(); // at least one document exists proceed

  app.activeDocument.suspendHistory('Fix Image to Guides','main()');  //problem if there is a selection a layer resize Photoshop back up a history step ?

}

///////////////////////////////////////////////////////////////////////////////

//                            main function                            

///////////////////////////////////////////////////////////////////////////////

function main() {

  // declare local variables

  var orig_ruler_units = app.preferences.rulerUnits;

  var orig_type_units = app.preferences.typeUnits;

  var orig_display_dialogs = app.displayDialogs;

  app.preferences.rulerUnits = Units.PIXELS; // Set the ruler units to PIXELS

  app.preferences.typeUnits = TypeUnits.POINTS;   // Set Type units to POINTS

  app.displayDialogs = DialogModes.NO; // Set Dialogs off

  try { code(); }

  // display error message if something goes wrong

  catch(e) { alert(e + ': on line ' + e.line, 'Script Error', true); }

  app.displayDialogs = orig_display_dialogs; // Reset display dialogs

  app.preferences.typeUnits  = orig_type_units; // Reset ruler units to original settings

  app.preferences.rulerUnits = orig_ruler_units; // Reset units to original settings

}

///////////////////////////////////////////////////////////////////////////////

//                           main function end                           

///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////

// The real code is embedded into this function so that at any point it can return

// to the main line function to let it restore users edit environment and end     

//////////////////////////////////////////////////////////////////////////////////////////////

function code() {

  if (app.activeDocument.guides.length != 4) { alert("Four and only four Guides are required"); return; } // quit

  // get guides;

  var theVert = new Array;

  var theHor = new Array;

  for (var m = 0; m < app.activeDocument.guides.length; m++) {

  if (app.activeDocument.guides.direction == Direction.HORIZONTAL) {theVert.push(app.activeDocument.guides.coordinate)}

  else {theHor.push(app.activeDocument.guides.coordinate)}

    };

  if (theHor.length != 2 || theVert.length != 2) { alert("Four Guides two vertical and two horizontal are required"); return; } // quit

  getTarget=getSelectedLayersIdx();

  if (getTarget.length!=1){ alert("The number of layers targeted is " + getTarget.length ); return; } // quit

  if (app.activeDocument.activeLayer.isBackgroundLayer ) { alert("Can not resize the background layer"); return; } // quit

  if (!app.activeDocument.activeLayer.visible ) { alert("Active layer is  not visible"); return; } // quit

  //if (hasLayerMask()) { alert("Active layer is  Masked"); return; } // quit

  if (app.activeDocument.activeLayer.kind == LayerKind.NORMAL  || app.activeDocument.activeLayer.kind == LayerKind.SMARTOBJECT && hasLayerMask()) { deleteLayerMask ();}

  if (app.activeDocument.activeLayer.kind != LayerKind.NORMAL  && app.activeDocument.activeLayer.kind != LayerKind.SMARTOBJECT )  {

  alert("Active layer is " + app.activeDocument.activeLayer.kind); return; } // quit

  // set selection to the area defined but the guide lines the selection may get undone by the bug in .resize() backing up a step in histoty ???

  app.activeDocument.selection.select([[theHor[0], theVert[0]], [theHor[1], theVert[0]], [theHor[1], theVert[1]], [theHor[0], theVert[1]]]);

  // resize current normal layer or smart object layer to just cover selection canvas area aspect ratio and size and mask off any overflow

  var SB = app.activeDocument.selection.bounds; // Get selection bounds

  var SWidth = (SB[2].value) - (SB[0].value); // Area width

  var SHeight = (SB[3].value) - (SB[1].value); // Area height

  var LB = app.activeDocument.activeLayer.bounds; // Get Active layers bounds

  var LWidth = (LB[2].value) - (LB[0].value); // Area width

  var LHeight = (LB[3].value) - (LB[1].value); // Area height

  var userResampleMethod = app.preferences.interpolation; // Save interpolation settings

  app.preferences.interpolation = ResampleMethod.BICUBIC; // resample interpolation bicubic

  app.activeDocument.selection.deselect(); // This deselect work around Adobe Bug in CS5, CS6, CC and CC 2014

  // Since Adobe does not fix old releases of Photoshop this is a necessary work around for many releases of Photoshop

  //alert("Before re-size history");  // Added to debug Adobe Resize Bug

  try {

  if (LWidth/LHeight<SWidth/SHeight) { // layer's Aspect Ratio less the Canvas area Aspect Ratio

  var percentageChange = ((SWidth/LWidth)*100); // Resize to canvas area width

  app.activeDocument.activeLayer.resize(percentageChange,percentageChange,AnchorPosition.MIDDLECENTER);

  }

  else {

  var percentageChange = ((SHeight/LHeight)*100); // resize to canvas area height

  app.activeDocument.activeLayer.resize(percentageChange,percentageChange,AnchorPosition.MIDDLECENTER);

  }

  }

  catch(e) {

  app.preferences.interpolation = userResampleMethod; // Reset interpolation setting

  selectFront(); // Photoshop make top layer current when none are targeted

  code(); // Retry  with top visible layer selected targeted

  return; // rest would have been done during the retry

  }

  //alert("After re-size history");    // Added to debug Adobe Resize Bug

  app.preferences.interpolation = userResampleMethod; // Reset interpolation setting

  // Seems to be a bug in  resize() the document seems to first be backed up a step in history

  app.activeDocument.selection.select([[theHor[0], theVert[0]], [theHor[1], theVert[0]], [theHor[1], theVert[1]], [theHor[0], theVert[1]]]); // redo the selection

  align('AdCH'); // align to horizontal centers

  align('AdCV'); // align to vertical centers

  addLayermask(); // add layer mask to mask off excess

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Helper Functions

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function align(method) {

  var desc = new ActionDescriptor();

  var ref = new ActionReference();

  ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

  desc.putReference( charIDToTypeID( "null" ), ref );

  desc.putEnumerated( charIDToTypeID( "Usng" ), charIDToTypeID( "ADSt" ), charIDToTypeID( method ) );

  try{executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );}

  catch(e){}

}

///////////////////////////////////////////////////////////////////////////////  

// Function: hasLayerMask  

// Usage: see if there is a raster layer mask  

// Input: <none> Must have an open document  

// Return: true if there is a vector mask  

///////////////////////////////////////////////////////////////////////////////  

function hasLayerMask() {  

  var hasLayerMask = false;  

  try {  

  var ref = new ActionReference();  

  var keyUserMaskEnabled = app.charIDToTypeID( 'UsrM' );  

  ref.putProperty( app.charIDToTypeID( 'Prpr' ), keyUserMaskEnabled );  

  ref.putEnumerated( app.charIDToTypeID( 'Lyr ' ), app.charIDToTypeID( 'Ordn' ), app.charIDToTypeID( 'Trgt' ) );  

  var desc = executeActionGet( ref );  

  if ( desc.hasKey( keyUserMaskEnabled ) ) { hasLayerMask = true; }  

  }

  catch(e) { hasLayerMask = false; }  

  return hasLayerMask;  

}  

function getSelectedLayersIdx(){

      var selectedLayers = new Array;

      var ref = new ActionReference();

      ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

      var desc = executeActionGet(ref);

      if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){

         desc = desc.getList( stringIDToTypeID( 'targetLayers' ));

          var c = desc.count

          var selectedLayers = new Array();

          for(var i=0;i<c;i++){

            try{

               activeDocument.backgroundLayer;

               selectedLayers.push(  desc.getReference( i ).getIndex() );

            }catch(e){

               selectedLayers.push(  desc.getReference( i ).getIndex()+1 );

            }

          }

       }else{

         var ref = new ActionReference();

         ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));

         ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

         try{

            activeDocument.backgroundLayer;

            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);

         }catch(e){

            selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));

         }

      }

      return selectedLayers;

};

function selectFront() {

// Alt+. shortcut select ftont visible layer

var idslct = charIDToTypeID( "slct" );

    var desc250 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref207 = new ActionReference();

        var idLyr = charIDToTypeID( "Lyr " );

        var idOrdn = charIDToTypeID( "Ordn" );

        var idFrnt = charIDToTypeID( "Frnt" );

        ref207.putEnumerated( idLyr, idOrdn, idFrnt );

    desc250.putReference( idnull, ref207 );

    var idMkVs = charIDToTypeID( "MkVs" );

    desc250.putBoolean( idMkVs, false );

executeAction( idslct, desc250, DialogModes.NO );

}

function deleteLayerMask (apply) {

// Delet Layer mask default to not apply first

if (apply == undefined) {var apply = false};

try {

var idDlt = charIDToTypeID( "Dlt " );

    var desc9 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref5 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idChnl = charIDToTypeID( "Chnl" );

        var idMsk = charIDToTypeID( "Msk " );

        ref5.putEnumerated( idChnl, idChnl, idMsk );

    desc9.putReference( idnull, ref5 );

    var idAply = charIDToTypeID( "Aply" );

    desc9.putBoolean( idAply, apply );

executeAction( idDlt, desc9, DialogModes.NO );

}

catch (e) {}

};

function addLayermask(){

// Add layer Mask

var idMk = charIDToTypeID( "Mk  " );

    var desc52 = new ActionDescriptor();

    var idNw = charIDToTypeID( "Nw  " );

    var idChnl = charIDToTypeID( "Chnl" );

    desc52.putClass( idNw, idChnl );

    var idAt = charIDToTypeID( "At  " );

        var ref19 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

        var idChnl = charIDToTypeID( "Chnl" );

        var idMsk = charIDToTypeID( "Msk " );

        ref19.putEnumerated( idChnl, idChnl, idMsk );

    desc52.putReference( idAt, ref19 );

    var idUsng = charIDToTypeID( "Usng" );

    var idUsrM = charIDToTypeID( "UsrM" );

    var idRvlS = charIDToTypeID( "RvlS" );

    desc52.putEnumerated( idUsng, idUsrM, idRvlS );

executeAction( idMk, desc52, DialogModes.NO );

// Un link layer mask just added fron the layers content

var idsetd = charIDToTypeID( "setd" );

    var desc2 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref1 = new ActionReference();

        var idLyr = charIDToTypeID( "Lyr " );

        var idOrdn = charIDToTypeID( "Ordn" );

        var idTrgt = charIDToTypeID( "Trgt" );

        ref1.putEnumerated( idLyr, idOrdn, idTrgt );

    desc2.putReference( idnull, ref1 );

    var idT = charIDToTypeID( "T   " );

        var desc3 = new ActionDescriptor();

        var idUsrs = charIDToTypeID( "Usrs" );

        desc3.putBoolean( idUsrs, false );

    var idLyr = charIDToTypeID( "Lyr " );

    desc2.putObject( idT, idLyr, desc3 );

executeAction( idsetd, desc2, DialogModes.NO );

}

JJMack
Known Participant
May 3, 2016

Great!

JJMack
Community Expert
Community Expert
May 3, 2016

That look like it may be canvas size a backgroung layer.  Layers do not need to be canvas size or even over the canvas.  Many kate bounds do not have a 0.0 origin. All  layer bound are rectangle bit the layer can have emoth oixel be any shape.

This script will set guides on layer bounds and and across its bounds centers.

// enable double-clicking from Mac Finder or Windows Explorer

#target photoshop // this command only works in Photoshop CS2 and higher

// bring application forward for double-click events

app.bringToFront();

// Save the current preferences

var startRulerUnits = app.preferences.rulerUnits;

// Set Photoshop to use pixels

app.preferences.rulerUnits = Units.PIXELS;

try{

  var LB = activeDocument.activeLayer.bounds;

  var LWidth = (LB[2].value) - (LB[0].value);

  var LHeight = (LB[3].value) - (LB[1].value);

  MarkX((LB[0].value + LWidth/2));

  MarkX(LB[0].value);

  MarkX(LB[2].value);

  MarkY((LB[1].value + LHeight/2));

  MarkY(LB[1].value)

  MarkY(LB[3].value)

  alert("'" + activeDocument.activeLayer.name + "' Layer Bounds\nTop Left " +  LB[0].value + "X," +  LB[1].value + "Y   Bottom Right "  +  LB[2].value + "X," +  LB[3].value

  + "Y\nWidth " +  LWidth + "px   Height " + LHeight +"px"

  + "\nLayer center relative to canvas " + (LB[0].value + LWidth/2) + "X," +  (LB[1].value + LHeight/2) +"Y"

  );

}

catch(e){alert("Requires a layer targered");}

// Return the app preferences

app.preferences.rulerUnits = startRulerUnits;

function MarkX(x) {

// =======================================================

var idMk = charIDToTypeID( "Mk  " );

    var desc61 = new ActionDescriptor();

    var idNw = charIDToTypeID( "Nw  " );

        var desc62 = new ActionDescriptor();

        var idPstn = charIDToTypeID( "Pstn" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc62.putUnitDouble( idPstn, idPxl, x);

        var idOrnt = charIDToTypeID( "Ornt" );

        var idOrnt = charIDToTypeID( "Ornt" );

        var idVrtc = charIDToTypeID( "Vrtc" );

        desc62.putEnumerated( idOrnt, idOrnt, idVrtc );

    var idGd = charIDToTypeID( "Gd  " );

    desc61.putObject( idNw, idGd, desc62 );

executeAction( idMk, desc61, DialogModes.NO );

}

function MarkY(y) {

// =======================================================

var idMk = charIDToTypeID( "Mk  " );

    var desc63 = new ActionDescriptor();

    var idNw = charIDToTypeID( "Nw  " );

        var desc64 = new ActionDescriptor();

        var idPstn = charIDToTypeID( "Pstn" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc64.putUnitDouble( idPstn, idPxl, y );

        var idOrnt = charIDToTypeID( "Ornt" );

        var idOrnt = charIDToTypeID( "Ornt" );

        var idHrzn = charIDToTypeID( "Hrzn" );

        desc64.putEnumerated( idOrnt, idOrnt, idHrzn );

    var idGd = charIDToTypeID( "Gd  " );

    desc63.putObject( idNw, idGd, desc64 );

executeAction( idMk, desc63, DialogModes.NO );

}

JJMack
Known Participant
May 3, 2016

Hi JJMack: Thank you,.  I can get the "coordinates" of a layer with the following code (couldn't figure out if there is a way to set the font in an alert statement); but have not yet tried to use the exposed variables with placing guides or doing a crop.

#target photoshop

// bring application forward for double-click events

app.bringToFront();

// Save the current preferences

var startRulerUnits = app.preferences.rulerUnits;

// Set Photoshop to use pixels

app.preferences.rulerUnits = Units.PIXELS;

var LB = activeDocument.activeLayer.bounds;

$.writeln(LB);

//alert("ok",LB);

var LWidth = (LB[2].value) - (LB[0].value);

var LHeight = (LB[3].value) - (LB[1].value);

sp1 = pad (" ",14," ");

sp2 = pad (" ",19," ");

sp3 = pad (" ",2," ");

sp4 = pad (" ",17," ");

sp5 = pad (" ",3," ");

alert

(

"top  L = " +sp1+      LB[0].value + "," +sp4+                LB[1].value + "\n" +

"top  R = " +sp1+      LB[0].value + "," +sp3+ "over"  +sp5+  LB[2].value + "\n" +

"lowr L = " +sp1+      LB[0].value + "," +sp3+ "down"  +sp5+  LB[3].value + "\n" +

"lowr R = "+" over " + LB[3].value + "," +sp3+ "down"  +sp5+  LB[2].value + "\n"

);

// Return the app preferences

app.preferences.rulerUnits = startRulerUnits;

function pad ( orig , count , padWith ) {

//-- eps@electronicpublishingsupport.com

var padChar = "0" ;

//-- but if they sent something, use the first character of it

if ( padWith != undefined ) { padChar = String (padWith).substr (0,1) ; }

//-- Convert to a string (actually adding the "" to it would have worked.)

var withThis = String ( orig ) + '' ;

//-- Check its length, with it is long enought return. Until then keep

//--  adding the padChar

while ( count > withThis.length) {

  withThis = padChar + withThis;

  }

//-- Back to the caller

return withThis;

}

//

Known Participant
May 2, 2016

Thank you TEvashkevich:  I need to do this to a number of photos.  Sometimes the swatch is on top, sometimes on the side, etc.  I always have to zoom in to figure out just where the last guide should be placed. Some images need to be rotated, etc.  Once I figure out (or someone else does) the crop script, I thought that I might use the configurator, to create a panel, with different icons: one for the case where the swatch was on the bottom, etc.  Since I am new to adobe scripting, it is hard for me to know whether I should use scriptUI, or what.  But the scripts are running very fast out of the ExtendScript Tool, although the variable window takes some getting used to.  And, in the main screen, in debug mode, if you hold your mouse over a variable, it doesn't show its value.  Thanks again, Steve

999tevashkevich
Known Participant
May 2, 2016

Yeah extendscript is garbage for debugging (imo...)

I'll see if I can whip you up something (I'll likely just toss it through config anyways cause if I'm gonna make a UI I mid as well just do that anyways)