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

How to get Ruler Tool angle measurement

Community Beginner ,
May 06, 2015 May 06, 2015

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

TOPICS
Actions and scripting
3.4K
Translate
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

correct answers 1 Correct answer

Community Expert , May 06, 2015 May 06, 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(stringIDToTyp

...
Translate
Adobe
Community Expert ,
May 06, 2015 May 06, 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

  };

Translate
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 ,
May 06, 2015 May 06, 2015

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

Translate
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 ,
May 06, 2015 May 06, 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. 

Translate
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 ,
May 06, 2015 May 06, 2015

I should spend some more time with the AM code. I actually asked Jeff about this exact same thing, and he replied that AM was "Dark magic."

Translate
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 ,
May 06, 2015 May 06, 2015

Thanks a lot Cristoph!

I'm pretty new with JS (couple of months) and it still look strange to me that something as simple as a readout from a tool needs all that code. I mean since Photoshop already made all the calculations why should I do them again? Really don't get this.

If I understand correctly this is sort of hand-written-scripting-listener kind of code, isn't it?

Anyway I will test it deeply but the first impression is: it works! 🙂

Thanks again,

MD

Translate
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 ,
May 06, 2015 May 06, 2015

Who knows, maybe the angle is available somewhere – but Script-performance-wise the calculation based on two points should be close to negligible.

Translate
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
Advocate ,
May 06, 2015 May 06, 2015

Hi Christoph,

do you happen to know why the point ActionList contains 3 points? It seems like point 0 and point 1 are the same, while point 2 is the second one.

Thank you!

Davide

Translate
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 ,
May 06, 2015 May 06, 2015

Sorry, I don’t know that either.

Translate
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
New Here ,
Sep 01, 2016 Sep 01, 2016
LATEST

Hi Davide,

I stumbled here searching for a way extract the L1 and L2 values without the need to calculate.

I can answer your question though. Point 0 is used when you draw an angle by holding Alt using the Ruler Tool.

Mystery solved 🙂

P.

angle.jpg

Translate
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