create selection based on guides

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Mcquiff

create selection based on guides

Post by Mcquiff »

I have an image. where I drag 4 guides, 2 horizontal and 2 vertical. so they create a box around the image.

I've no photoshop scripting knowledge only applescript. So with this box I would like to create a marquee that fits it.

Is this possible?

Thanks
Matt

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

pfaffenbichler

create selection based on guides

Post by pfaffenbichler »

Does this help?
Code: Select all// make rectangular selection based on 4 guides;
// 2014, use at your own risk;
#target "photoshop-70.032"
if (app.documents.length > 0) {main()};
////// function //////
function main () {
// set to pixels;
var myDocument = app.activeDocument;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
if (myDocument.guides.length == 4) {
// get guides;
var theVert = new Array;
var theHor = new Array;
for (var m = 0; m < myDocument.guides.length; m++) {
   if (myDocument.guides[m].direction == Direction.HORIZONTAL) {theVert.push(myDocument.guides[m].coordinate)}
   else {theHor.push(myDocument.guides[m].coordinate)}
   };
// make selection;
myDocument.selection.select([[theHor[0], theVert[0]], [theHor[1], theVert[0]], [theHor[1], theVert[1]], [theHor[0], theVert[1]]]);
};
// reset;
app.preferences.rulerUnits = originalRulerUnits;
};
Mcquiff

create selection based on guides

Post by Mcquiff »

Absolutly perfect thanks!!
pfaffenbichler

create selection based on guides

Post by pfaffenbichler »

Actually I forgot to check whether the vertical and horizontal guides are two each.
Please replace
Code: Select allmyDocument.selection.select([[theHor[0], theVert[0]], [theHor[1], theVert[0]], [theHor[1], theVert[1]], [theHor[0], theVert[1]]]);
with
Code: Select allif (theHor.length == 2 && theVert.length == 2)
{myDocument.selection.select([[theHor[0], theVert[0]], [theHor[1], theVert[0]], [theHor[1], theVert[1]], [theHor[0], theVert[1]]])
};