Photoshop: Add guides to a selection (a javascript solution)

  • 1
  • Idea
  • Updated 6 years ago
  • (Edited)
I posted this question as part of a thread on deleting paths. But as Paul Riggott was kind enough to write a script to solve my need, I thought I'd post the need here along with Paul's script.

The Need: to be able to add guides to a square or rectangular selection.
The Why: On most of the commercial photos I shoot, I need to put cropping guides on the photo so that later, the client or anyone, would have an idea of what I / we were thinking when the photo was created. I make a selection of the cropped area and then drag out 4 guides to the sides of the selection. This procedure is done over and over. So I wanted to way to speed up process. One click.

Open up Photoshop ExtendKit application (it came with Photoshop). Create a new document, copy and paste the code in the window. Save as (give it a name) in applications > Photoshop CSx (x is you version, mine is CS5) > presets > Scripts
Close photoshop if it was open, relaunch so it can load the new script.

Here is the code Paul provided to do just that:

#target Photoshop
main();
function main(){
if(!documents.length) return;
var startRulerUnits = preferences.rulerUnits;
try{
preferences.rulerUnits = Units.PIXELS
var SB = activeDocument.selection.bounds;
}catch(e){return;}
guideLine(SB[1].value,"Hrzn");
guideLine(SB[3].value,"Hrzn");
guideLine(SB[0].value,"Vrtc");
guideLine(SB[2].value,"Vrtc");
preferences.rulerUnits = startRulerUnits;
}
function guideLine(position, type){
var desc = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putUnitDouble( app.charIDToTypeID('Pstn'), app.charIDToTypeID('#Pxl'), position );
desc2.putEnumerated( app.charIDToTypeID('Ornt'), app.charIDToTypeID('Ornt'), app.charIDToTypeID(type) );
desc.putObject( app.charIDToTypeID('Nw '), app.charIDToTypeID('Gd '), desc2 );
executeAction( app.charIDToTypeID('Mk '), desc, DialogModes.NO );
};

Thanks Paul for your valuable skills!

JeffN
Photo of Jeff Natrop

Jeff Natrop

  • 33 Posts
  • 1 Reply Like

Posted 6 years ago

  • 1

Be the first to post a reply!