Skip to main content
marco mda
Participant
May 6, 2015
Answered

How to get Ruler Tool angle measurement

  • May 6, 2015
  • 1 reply
  • 3467 views

Good afternoon all,

I'm struggling to find a way on how to use the angle displayed when tracing a line with the ruler tool.

This is in order to amend a script that now uses as a condition the width of the active layer: if bigger than n px do this, else do that. It just works fine.

I need to do the same but using the angle traced by a user (before running the script).

BUT I cannot find a way to use that angle measure.

Any help please?

Thanks a lot,

MD

This topic has been closed for replies.
Correct answer c.pfaffenbichler

Does this help?

// 2015, use it at your own risk;

#target photoshop

var ref = new ActionReference();

ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var docDesc = executeActionGet(ref);

var point = docDesc.getList(stringIDToTypeID("points"));

var p1 = [point.getObjectValue(1).getUnitDoubleValue(stringIDToTypeID("x")), point.getObjectValue(1).getUnitDoubleValue(stringIDToTypeID("y"))];

var p2 = [point.getObjectValue(2).getUnitDoubleValue(stringIDToTypeID("x")), point.getObjectValue(2).getUnitDoubleValue(stringIDToTypeID("y"))];

var angle = 360- getAngle (p1, p2);

alert (angle);

////// get an angle, 3:00 being 0˚, 6:00 90˚, etc. //////

function getAngle (pointOne, pointTwo) {

// calculate the triangle sides;

  var width = pointTwo[0] - pointOne[0];

  var height = pointTwo[1] - pointOne[1];

  var sideC = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));

// calculate the angles;

  if (width+width > width) {theAngle = Math.asin(height / sideC) * 360 / 2 / Math.PI}

  else {theAngle = 180 - (Math.asin(height / sideC) * 360 / 2 / Math.PI)};

  if (theAngle < 0) {theAngle = (360 + theAngle)};

  return theAngle

  };

1 reply

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
May 6, 2015

Does this help?

// 2015, use it at your own risk;

#target photoshop

var ref = new ActionReference();

ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var docDesc = executeActionGet(ref);

var point = docDesc.getList(stringIDToTypeID("points"));

var p1 = [point.getObjectValue(1).getUnitDoubleValue(stringIDToTypeID("x")), point.getObjectValue(1).getUnitDoubleValue(stringIDToTypeID("y"))];

var p2 = [point.getObjectValue(2).getUnitDoubleValue(stringIDToTypeID("x")), point.getObjectValue(2).getUnitDoubleValue(stringIDToTypeID("y"))];

var angle = 360- getAngle (p1, p2);

alert (angle);

////// get an angle, 3:00 being 0˚, 6:00 90˚, etc. //////

function getAngle (pointOne, pointTwo) {

// calculate the triangle sides;

  var width = pointTwo[0] - pointOne[0];

  var height = pointTwo[1] - pointOne[1];

  var sideC = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));

// calculate the angles;

  if (width+width > width) {theAngle = Math.asin(height / sideC) * 360 / 2 / Math.PI}

  else {theAngle = 180 - (Math.asin(height / sideC) * 360 / 2 / Math.PI)};

  if (theAngle < 0) {theAngle = (360 + theAngle)};

  return theAngle

  };

Chuck Uebele
Community Expert
Community Expert
May 6, 2015

Nice, Christoph! I was looking at something like this for a project, but I still have issues with AM code.

c.pfaffenbichler
Community Expert
Community Expert
May 6, 2015

Oh, I have issues with that as well …

But fortunately with past advice from and some code by the usual suspects I can work out some stuff.