Copy link to clipboard
Copied
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
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
Copy link to clipboard
Copied
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
};
Copy link to clipboard
Copied
Nice, Christoph! I was looking at something like this for a project, but I still have issues with AM code.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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."
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Who knows, maybe the angle is available somewhere – but Script-performance-wise the calculation based on two points should be close to negligible.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Sorry, I don’t know that either.
Copy link to clipboard
Copied
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.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now