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
create selection based on guides
-
pfaffenbichler
create selection based on guides
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;
};
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;
};
-
pfaffenbichler
create selection based on guides
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]]])
};
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]]])
};