• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Run script based on pixel location?

Community Beginner ,
Jan 23, 2015 Jan 23, 2015

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

TOPICS
Actions and scripting

Views

623

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Jan 23, 2015 Jan 23, 2015

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.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 23, 2015 Jan 23, 2015

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 }

  }

},

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 24, 2015 Jan 24, 2015

Copy link to clipboard

Copied

Thanks for the Replies.

... and thanks for the script, Matias!

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2015 Jan 24, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2015 Jan 24, 2015

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

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 24, 2015 Jan 24, 2015

Copy link to clipboard

Copied

LATEST

Thanks for the code, c.pfaffenbichler!

this should be a good place to start.

Jeff

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines