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

How can I determine the rotate angle of an artLayer?

Engaged ,
Sep 13, 2012 Sep 13, 2012

Copy link to clipboard

Copied

I have a document with multiple layers. I can rotate a layer via the script. However, if the layer is already rotated via some angle, how can i determine that via the script?

TOPICS
Actions and scripting

Views

2.8K

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 ,
Sep 14, 2012 Sep 14, 2012

Copy link to clipboard

Copied

What are you talking about?

Smart Objects or regular Layers (of the various kinds)?

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
Engaged ,
Sep 14, 2012 Sep 14, 2012

Copy link to clipboard

Copied

I am talking about the regular layers.

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 ,
Sep 14, 2012 Sep 14, 2012

Copy link to clipboard

Copied

I may be misunderstanding youe question, but if you rotate a pixel Layer and once the rotation step is not in the History or in a Log anymore, then there is no real (edit: in the sense of enabling Photoshop to determine it unequivocally) information on whether and how much it has been rotated.

Image content like discernable stripes may make it clear to you that an element has been rotated, but that is hardly for Photoshop to decide.

One could evaluate a Layer’s transparency to see if it more or less conforms to a rectangle and then determine the angles, but as the Layer may have been created that way that would seem to be a judgement call.

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
Engaged ,
Sep 14, 2012 Sep 14, 2012

Copy link to clipboard

Copied

Thanks for your quick responses. Yes, you are right. One can not determine the rotate angle.

Is the above understanding different if the layer would have been Smart Objects. Can we determine the angle then?

Also, i have another question related to rotate. I am fetching the bounds of a layer, then i am rotating the layer via certain angle and then again fetching the bounds. The both bounds are coming same. This should not be the case because after rotating the layer, the bounding rectangle to the layer changes and hence the bounds should change. Do I need to save the document after rotating the layer and then fetch the bounds again?

Thanks again.

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
Guru ,
Sep 14, 2012 Sep 14, 2012

Copy link to clipboard

Copied

Untried but have you app.refresh() between the rotate and get new bounds… don't know it that will make a difference?

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 ,
Sep 14, 2012 Sep 14, 2012

Copy link to clipboard

Copied

if the layer would have been Smart Objects. Can we determine the angle then?

I’m afraid while the information naturally has to be stored I don’t know how to access it or if it is even possible.

The both bounds are coming same.

Could the layer have almost invisible pixels that basically make it square?

Apart from Mark’s recommendation I don’t know how to remedy that either, but in a quick test the bounds seem to update on my station.

Are you sure you got the bounds anew after the transformation and have not set a variable of the bounds prior?

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 ,
Sep 14, 2012 Sep 14, 2012

Copy link to clipboard

Copied

If you know that a Layer is a rotated rectangule one could, as mentioned earlier, try to use its transparency to determine the rotation to the closest 90˚ – if it had been rotated 180˚ for example that would not register.

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
Engaged ,
Sep 16, 2012 Sep 16, 2012

Copy link to clipboard

Copied

If you know that a Layer is a rotated rectangule

Yes. The layer is a rotated rectangle. Please elaborate on how can i fetch the transparency values and how can i calculate the rotation to the closest 90.

Thanks again.

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
Guru ,
Sep 16, 2012 Sep 16, 2012

Copy link to clipboard

Copied

You can't get the angle directly from the layer's transparency. You can load the transparency as a selection. Make a path from that selection. Then examine the pathPoints to find an angle in the path. With a simple rectanglar shaped layer you should be able to get close to the correct angle if it was only rotated once and less than +- 89 degrees.

function loadTransparency(){

    var desc = new ActionDescriptor();

        var ref = new ActionReference();

        ref.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );

    desc.putReference( charIDToTypeID( "null" ), ref );

        var ref1 = new ActionReference();

        ref1.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Trsp" ) );

    desc.putReference( charIDToTypeID( "T   " ), ref1 );

    executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );

};

function makePathFromSelection() {

    var desc = new ActionDescriptor();

        var ref = new ActionReference();

        ref.putClass( charIDToTypeID('Path') );

    desc.putReference( charIDToTypeID('null'), ref );

        var channelRef = new ActionReference();

        channelRef.putProperty( charIDToTypeID('csel'), charIDToTypeID('fsel') );

    desc.putReference( charIDToTypeID('From'), channelRef );

    desc.putUnitDouble( charIDToTypeID('Tlrn'), charIDToTypeID('#Pxl'), 2.000000 );

    executeAction( charIDToTypeID('Mk  '), desc, DialogModes.NO );

};

function activePathIndex(){

    try{

        var ref = new ActionReference();

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

        var desc = executeActionGet( ref );

        return  desc.getInteger(charIDToTypeID("TrgP" ));

    }catch(e){}

};

function measureAngle(path){

   var res = new Array;

   var lineStart = path.subPathItems[0].pathPoints[0].anchor;

   var lineEnd = path.subPathItems[0].pathPoints[1].anchor;

   var a = Math.max(lineStart[0],lineEnd[0])-Math.min(lineStart[0],lineEnd[0]);

   var o = Math.max(lineStart[1],lineEnd[1])-Math.min(lineStart[1],lineEnd[1]);

   var c = Math.round(Math.sqrt((a*a)+(o*o)));

   res.push(c);

   var ang = (180/Math.PI) * Math.atan2(o,a);

   if(lineStart[1] < lineEnd[1]){//negative angle

      ang = -ang;

   };

   res.push(ang);

   return res;

};

loadTransparency();

makePathFromSelection();

var tempPath = app.activeDocument.pathItems[activePathIndex()];

var angle = measureAngle( tempPath )[1];

tempPath.remove();

alert( Math.abs(angle) );

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
Explorer ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

LATEST

This is the best code for measuring the layer angles! Many thanks!

 

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
Valorous Hero ,
Sep 16, 2012 Sep 16, 2012

Copy link to clipboard

Copied

You can create a linked and disabled vector mask with only two ancor points and determine the rotation of the layer via calculations points coordinates.

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