23 Replies Latest reply on Aug 13, 2018 11:55 AM by r-bin

    Get Layer Transform X Y Top Left Coordinate Position

    X-Raym Level 1

      Hi !

       

      I try to look for this but in fact it seems more complicated than expected, and I didn't find a working up to date solution.

       

      So we have layer bound property, which can return top left value of a layer.

       

      But if the layer is smart layer (or a text) this may not work as I would have expect: indeed, it will return the value of the position of the first pixel, and not the actual smart layer position (determined by it's original boundaries).

       

      Here is a screen capture to show the difference between the layer top left coordinate and the transform X Y position (which match the original file placement):

       

       

      How do you get these X Y positions from a Photoshop script ?

       

      Thanks !

        • 2. Re: Get Layer Transform X Y Top Left Coordinate Position
          X-Raym Level 1

          r-bin

          Hi, thanks for your very quick assistance (and your initial code snippet) !

           

          This get_smart_object_corners() function doesn't take any parameter, how come ?

          How to pass a Layer as parameter to it ?

           

          My ultimate goal is to merge this code snippet to

           

          Adobe-Export-Scripts/Export Layer Coordinates Photoshop.jsx at master · bronzehedwick/Adobe-Export-Scripts · GitHub

           

          As you can see L44, the function need to take a Layer as parameter.

           

          Many thanks again!

           

          (let me know if you prefer me to answer in the original thread).

          • 3. Re: Get Layer Transform X Y Top Left Coordinate Position
            r-bin Level 5

            Try this function

             

            function get_layer_bounds(layer)
                {
                try
                    {
                    if (layer.kind == LayerKind.SMARTOBJECT)
                        {
                        var layer0 = activeDocument.activeLayer;
                        activeDocument.activeLayer = layer;
            
                        var r = new ActionReference();
                        r.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
            
                        var d = executeActionGet(r).getObjectValue(stringIDToTypeID("smartObjectMore")).getList(stringIDToTypeID("transform"));
            
                        var x = [d.getDouble(0), d.getDouble(2), d.getDouble(4), d.getDouble(6)];
                        var y = [d.getDouble(1), d.getDouble(3), d.getDouble(5), d.getDouble(7)];
                       
                        var l = [Math.min(x[0], Math.min(x[1], Math.min(x[2], x[3]))) ];
                        var r = [Math.max(x[0], Math.max(x[1], Math.max(x[2], x[3]))) ];
            
                        var t = [Math.min(y[0], Math.min(y[1], Math.min(y[2], y[3]))) ];
                        var b = [Math.max(y[0], Math.max(y[1], Math.max(y[2], y[3]))) ];
            
                        activeDocument.activeLayer = layer0;
            
                        return [ UnitValue(l,"px"), UnitValue(t,"px"), UnitValue(r,"px"), UnitValue(b,"px") ];
                        }
                    else
                        return layer.boundsNoEffects;
                    }
                catch (e) { alert(e); }
                }
            
            2 people found this helpful
            • 4. Re: Get Layer Transform X Y Top Left Coordinate Position
              JJMack Most Valuable Participant

              I have never seen any code posted that can get a smart object layers associated transform setting.    Never seen code to get any of the scaling values.

               

              I see this function the gets the layers pixels bonds  where activeDoctment.activelayer.bounds may return a larger area if the layer has a layer style that extends outside the layers pixel area, like a drop shadow . 

               

              I have seen the code that you posted to get the layer transform four corners to calculate a rotation angle in CC 2018 that may work if the layer transform simply sized and rotated the object  by doing the right triangle math for the slope of a side after getting the layers four coners points.  However that will not be correct if the layers associated transform has some perspective or other distortion.    Also when I tested the function. The function did not return the transform's four corners.

               

              I have never seen code that can get the values that Photoshop shows in the transform tools option bar.  Fot the smart object layers assocated transform.

               

              Capture.jpg]

              2 people found this helpful
              • 5. Re: Get Layer Transform X Y Top Left Coordinate Position
                r-bin Level 5

                Ok. You can experiment by replacing "transform" with "nonAffineTransform".
                And also explore the "size" and "warp" objects in the smartObjectMore object.

                 

                I do not have time for this now )

                • 6. Re: Get Layer Transform X Y Top Left Coordinate Position
                  JJMack Most Valuable Participant

                  Perhaps you can but that is above my pay grade.  I do not know JavaScript or java objects structures to be able to parse them or process them well. Do not know to retriever some Photoshop information using action manager code.  I only modify Scriptlistener generated Action manager code you know the execute side of Action manger.

                   

                  I'm older and retired I look for code from younger whippersnappers so I can hack on it.   If I have to say it myself,  I will, I may need to use a sledge hammer  but I can hammer on javascript and often get it to do what I want it to do.

                   

                  The first place I look for code is hear searching this forum. And I'm sadden when great scripters like Paul leave when other like Mike pass away while X is still maintaining Image Processor Pro but only drops in here once in a while. In other words I need you to stay here.

                   

                  Thank you now that works well and has given me some other things to think about. It interesting to me  how the layers bounds area and the transform points area ciffer, Don't know if I can make any use out of that.

                  // Select Smart Object Layers Associated transform area  
                  app.activeDocument.selection.select(get_smart_object_corners());
                  ////////////////////////////////////////////////////////////////////////////////////////// //
                  function get_smart_object_corners() {
                      try
                          {
                          var r = new ActionReference();
                          r.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
                          var d;
                          try { d = executeActionGet(r); } catch (e) { alert(e); return; }
                          try { d = d.getObjectValue(stringIDToTypeID("smartObjectMore"));} catch (e) { alert(e); return; }
                          try { d = d.getList(stringIDToTypeID("nonAffineTransform"));} catch (e) { alert(e); return; }
                          var ret = [[d.getDouble(0),d.getDouble(1)],
                                     [d.getDouble(2),d.getDouble(3)],
                                     [d.getDouble(4),d.getDouble(5)],
                                     [d.getDouble(6),d.getDouble(7)]];
                          return ret;
                          }
                      catch (e) { alert(e); }
                  }
                  
                  2 people found this helpful