Copy link to clipboard
Copied
Is it possible for a script/Action to execute based on the coordinates of a pixels location, on a transparent layer?
Another words.. If a pixel is in coordinate X, run Script X,.. If its in coordinate Z, run Script Z.
Thanks
Jeff
Copy link to clipboard
Copied
I don't know of any way to make something like that a Photoshop event that would trigger a script or action.
Copy link to clipboard
Copied
Probably not like you say, but maybe you could achieve it in some other way. So if you mean you have a transparent layer with one just one pixel (or one solid block), you can find out coords by trimming it twice and noting how the dimensions change. So create an empty doc of same size, duplicate your layer there and trim it to find out x and y. Then you can keep running current script with those params or maybe eval a new script.
As an example see
trimDocument: function (doc) {
if (doc) {
var extents = {}
var orig_w = Photoshop.getDocumentWidth(doc)
var orig_h = Photoshop.getDocumentHeight(doc)
doc.trim(TrimType.TRANSPARENT, false, true, true, false)
var x = orig_w - Photoshop.getDocumentWidth(doc)
var y = orig_h - Photoshop.getDocumentHeight(doc)
doc.trim(TrimType.TRANSPARENT, true, false, false, true)
var h = Photoshop.getDocumentHeight(doc)
var w = Photoshop.getDocumentWidth(doc)
return { x: x, y: y, height: h, width: w }
}
},
Copy link to clipboard
Copied
Thanks for the Replies.
When I was referring to Coordinates. I meant the coordinates of the pixel, or dot (on a transparent layer ) in relation to the entire document area... not the dimensions of the pixel itself.
Think of a kind of grid system: a 512 x 512 document divided into 16 quadrants. If a dot is placed randomly on a transparent layer, the coordinates of that dot will trigger a script ( one of 16 ) depending on where it lies within the grid.
I know there are IF / THEN conditional events like this one..
http://www.ps-scripts.com/bb/viewtopic.php?t=69
I was wondering if a similar functionality could be applied to coordinate information.
Thanks for the help, and I am open to any other suggestions!
Jeff
Copy link to clipboard
Copied
If you can limit the requirement to the distance from the top and left it would be fairly easy, for the Layer’s pixel content’s center one could calculate that, too, though.
var theX = activeDocument.activeLayer.bounds[0];
var theY = activeDocument.activeLayer.bounds[1];
Then if-clauses or a switch-clause could be used to trigger operations based on those values.
Copy link to clipboard
Copied
How are the 16 Scripts different exactly?
Did you include setting the preferences.rulerUnits to Units.PIXELS in the Script?
Anyway, here is an example of how one could use numeric ranges in a switch-clause.
var theX = 35;
switch (true) {
case ((theX >= 0) && (theX < 10)):
alert ("0-10");
break;
case ((theX >= 10) && (theX < 20)):
alert ("10-20");
break;
case ((theX >= 20) && (theX < 30)):
alert ("20-30");
break;
case ((theX >= 30) && (theX < 40)):
alert ("30-40");
break;
case ((theX >= 40) && (theX < 50)):
alert ("40-50");
break;
case ((theX >= 50) && (theX < 60)):
alert ("50-60");
break;
default:
alert (">60");
break
};
Copy link to clipboard
Copied
Thanks for the code, c.pfaffenbichler!
this should be a good place to start.
Jeff