10 Replies Latest reply on Feb 5, 2015 10:03 AM by TomT-shirts

    What sort of coordinates/units do the Action Manger's "Place" command use?

    TomT-shirts Level 1

      I used Scripting Listener to make this Applescript function to place images. I have to place a bunch of different images very specifically on the canvas. I'm getting each image's dimensions in pixels and then I need to do some math based on the dimensions and use that to feed the correct "xCoordinate" and "yCoordinate" variables into this.


      The thing is, I can not figure out what on earth these numbers refer to. Pixels? Can't be, if I change the numbers, the inserted graphic does not jump the same number of pixels as the change in my value. The document's in inches, but it's not jumping the correct inch distance either. Is it points or picas or something? Is there any way for me to set the Info window to show me the same coordinates that will be used to determine placement the same way Action Manger code interprets it?


      Furthermore, it appears that if I change the size of the placed image, that it just comes in at some unpredictable location. If I place a 4" x 4" square 300 DPI image with this, then use the exact same "xCoordinate" and "yCoordinate" values and place a 2" x 2" 300 dpi image, they don't come in with anything I can recognize perfectly in common - the two images are not exactly aligned at the top, bottom, left, right, or center. And different times I place the same image with the same coordinates, I swear it sometimes comes in at different places if I went and did other things in between. So what is going on?


      Any help?


      Thanks,


      Tom.



      on place_image(filePath, xCoordinate, yCoordinate, imageScale)

             tell application"Adobe Photoshop CS6"

                     tell the current document

                           

                            do javascript "

      var idPlc= charIDToTypeID( \"Plc\" );

          var desc4 = new ActionDescriptor();

          var idnull = charIDToTypeID( \"null\" );

          desc4.putPath( idnull, new File( \"" & filePath& "\" ) );

          var idFTcs = charIDToTypeID( \"FTcs\" );

          var idQCSt = charIDToTypeID( \"QCSt\" );

          var idQcsa = charIDToTypeID( \"Qcsa\" );

          desc4.putEnumerated( idFTcs, idQCSt, idQcsa );

          var idOfst = charIDToTypeID( \"Ofst\" );

              var desc5 = new ActionDescriptor();

              var idHrzn= charIDToTypeID( \"Hrzn\" );

              var idRlt= charIDToTypeID( \"#Rlt\" );

              desc5.putUnitDouble( idHrzn, idRlt, " & xCoordinate & " );

              var idVrtc= charIDToTypeID( \"Vrtc\" );

              var idRlt= charIDToTypeID( \"#Rlt\" );

              desc5.putUnitDouble( idVrtc, idRlt, " & yCoordinate & " );

          var idOfst = charIDToTypeID( \"Ofst\" );

          desc4.putObject( idOfst, idOfst, desc5 );

          var idWdth = charIDToTypeID( \"Wdth\" );

          var idPrc = charIDToTypeID( \"#Prc\" );

          desc4.putUnitDouble( idWdth, idPrc, " & (imageScale) & " );

          var idHght = charIDToTypeID( \"Hght\" );

          var idPrc = charIDToTypeID( \"#Prc\" );

          desc4.putUnitDouble( idHght, idPrc, " & (imageScale) & " );

      executeAction( idPlc, desc4, DialogModes.NO );"

                     end tell

             end tell

      end place_image

       

        • 1. Re: What sort of coordinates/units do the Action Manger's "Place" command use?
          TomT-shirts Level 1

          OK, so a followup on this: it is using points, but it appears that this is just a bug when a document's at 18 DPI. When I work in a document at 18 DPI, I can place a graphic at coordinates 0, 0. Then place the same graphic at 100,100, but it does NOT place offset by 100,100 points. Then I can place it again at 0,0 and it places somewhere completely different from the first time! I can keep changing coordinates and then going back to 0,0 and it keeps going different places for every 0,0 placement!

           

          However, it's perfectly well behaved if I change the same document (without resampling) to 300 DPI. Then it's perfectly repeatable, and I can change the coordinates to whatever I want, and it comes in offset exactly that distance in points from the center of the canvas.

          • 2. Re: What sort of coordinates/units do the Action Manger's "Place" command use?
            JJMack Most Valuable Participant

            My Scripts are written in javascript. The place in images into templates where  image placements are mapped by Alpha Channels the can be any shape.   Image are  Fitted the fill the Mapped Image area and the Alpha channel is added as a layer mask to mask of any excess image.

             

            Photo Collage Toolkit

             

            Photoshop scripting is powerful and I believe this package demonstrates this A video showing a 5 image collage PSD template  being populates with images:

             

            The package includes four simple rules to follow when making Photo Collage Template PSD files so they will be compatible with my Photoshop scripts.

            1. Size the photo collage templates for the print size you want - width, height and print DPI resolution.
            2. Photo collage templates must have a Photoshop background layer. The contents of this layer can be anything.
            3. Photo collage templates must have alpha channels named "Image 1", "Image 2", ... "Image n".
            4. Photo collage templates layers above the background layers must provide transparent areas to let the images that will be placed below them show through.

             

            There are twelve scripts in this package they provide the following functions:

            1. TestCollageTemplate.jsx - Used to test a Photo Collage Template while you are making it with Photoshop.
            2. CollageTemplateBuilder.jsx - Can build Templates compatible with this toolkit's scripts.
            3. LayerToAlphaChan.jsx - Used to convert a Prototype Image Layer stack into a template document.
            4. InteractivePopulateCollage.jsx - Used to interactively populate Any Photo Collage template. Offers most user control inserting pictures and text.
            5. ReplaceCollageImage.jsx - use to replace a populated collage image Smart Object layer with an other image correctly resized and positioned.
            6. ChangeTextSize.jsx - This script can be used to change Image stamps text size when the size used by the populating did not work well.
            7. PopulateCollageTemplate.jsx - Used to Automatically populate a Photo Collage template and leave the populated copy open in Photoshop.
            8. BatchOneImageCollage.jsx - Used to Automatically Batch Populate Collage templates that only have one image inserted. The Collage or Image may be stamped with text.
            9. BatchMultiImageCollage.jsx - Used to Automatically Batch Populate Any Photo Collage template with images in a source image folder. Easier to use than the interactive script. Saved collages can be tweaked.
            10. BatchPicturePackage.jsx - Used to Automatically Batch Populate Any Photo Collage template with an image in a source image folder
            11. PasteImageRoll.jsx - Paste Images into a document to be print on roll paper.
            12. PCTpreferences.jsx - Edit This File to Customize Collage Populating scripts default setting and add your own Layer styles.

             

            Documentation and Examples

            • 3. Re: What sort of coordinates/units do the Action Manger's "Place" command use?
              pixxxel schubser MVP & Adobe Community Professional

              Hi TomT-shirts,

              there are more than one possibility.

              e.g. you can set your preferences to pixels and after script return to your own measurements.

               

              Perhaps this also could help.

              Replace your values in AM-Code (for horizontal and for vertical)

              var idHrzn= charIDToTypeID( \"Hrzn\" );

              var idRlt= charIDToTypeID( \"#Rlt\" );

              desc5.putUnitDouble( idHrzn, idRlt, " & xCoordinate & " );

               

              change to

              var idHrzn = charIDToTypeID( \"Hrzn\" );
              var idPxl = charIDToTypeID( \"#Pxl\" );
              desc5.putUnitDouble( idHrzn, idPxl, 20 ); // or your own value for " & xCoordinate & "
              
              

               

              Have fun

               

              • 4. Re: What sort of coordinates/units do the Action Manger's "Place" command use?
                TomT-shirts Level 1

                I wish it would let me edit the title of this posting to "Does anyone know how to make Action Manager "Place" use document coordinates, rather than coordinates relative to the display?"

                 

                OK, it took me forever to figure this out, but I've got it now... but the news isn't good. Using Action Manager to handle a place command, the place coordinates are.... relative to the current view! If you zoom and pan around a big document, the image, using this script, interprets these coordinates relative to the current view of the document, not anything absolute to the document itself. Which is death for my usage scenario... anyone know javascript better who can tell me if there's some setting for that? It seems like, if it were recorded as an action, it wouldn't do to have the action place graphics in different places based on the pan and zoom settings at the time it was run.

                 

                If I make a big document, at any resolution, and place a small image in it with this script at coordinates 0,0, if I zoom in anywhere on that document and run the script, the placed image always gets paced in the center of my screen. I can make it place the image in the very top left or bottom right corner of the document by just zooming around in between runs. Or in other words, the "place" coordinates are coordinates on my monitor, not in the document!

                 

                Any ideas on how I can get absolute coordinates? Is one of the things I don't recognize a specifier of "Absolute" versus "Relative" placement?

                • 5. Re: What sort of coordinates/units do the Action Manger's "Place" command use?
                  TomT-shirts Level 1
                  
                  change to
                  
                  
                  
                  1. var idHrzn = charIDToTypeID( \"Hrzn\" ); 
                  2. var idPxl = charIDToTypeID( \"#Pxl\" ); 
                  3. desc5.putUnitDouble( idHrzn, idPxl, 20 ); // or your own value for " & xCoordinate & " 

                   

                   

                  I made this change, and it's handy that it's in pixels, but I'm still have the trouble that placing the same image into the same document with the same coordinates, it still shows up in different places different times I run the script. See my last post - its placing it in coordinates on the display, not the document.

                  • 6. Re: What sort of coordinates/units do the Action Manger's "Place" command use?
                    pixxxel schubser MVP & Adobe Community Professional

                    Ok, there is still much to be done.

                     

                    But in the moment you can add these pure javascript in your originalscript (before the first end tell)

                    var aLayer = activeDocument.activeLayer;
                    var Pos = aLayer.bounds;
                    Pos[0] = 10 - Pos[0];  // 10 or your own value for " & xCoordinate & "  
                    Pos[1] = 10 - Pos[1];  // 10 or your own value for " & yCoordinate & "
                    aLayer.translate(-Pos[0],-Pos[1]);
                    
                    

                     

                    have fun

                     

                    • 7. Re: What sort of coordinates/units do the Action Manger's "Place" command use?
                      TomT-shirts Level 1

                      Thanks, this is a very helpful workaround to the weirdness of the "Place" ignoring document coordinates.

                       

                      I had just found a similar workaround myself - if there is a selection in the document, the placed image comes using the coordinates based on the center of the selection. So I made the coordinates in the Action Manager code a hard-coded "0,0" and inserted a line of Applescript that selects one pixel where I want the image centered. The function works the way I had in mind. I need to do more testing, but this appears to work, as long as I don't want the placed image to come in right at the edge of the document. If the selection is so close to the edge that the placed image would not be entirely on the canvas, it seems to ignore it. But that should be OK - I'm not trying to place anything off the canvas.

                       

                      Thanks for the help!

                       

                       

                      on place_image(filePath, xCoordinate, yCoordinate, imageScale)

                        tell application "Adobe Photoshop CS6"

                        tell the current document

                        select region {{xCoordinate, yCoordinate}, {xCoordinate + 1, yCoordinate}, {xCoordinate, yCoordinate + 1}, {xCoordinate + 1, yCoordinate + 1}}

                        display dialog "selected"

                        do javascript "

                      var idPlc = charIDToTypeID( \"Plc \" );

                          var desc4 = new ActionDescriptor();

                          var idnull = charIDToTypeID( \"null\" );

                          desc4.putPath( idnull, new File( \"" & filePath & "\" ) );

                          var idFTcs = charIDToTypeID( \"FTcs\" );

                          var idQCSt = charIDToTypeID( \"QCSt\" );

                          var idQcsa = charIDToTypeID( \"Qcsa\" );

                          desc4.putEnumerated( idFTcs, idQCSt, idQcsa );

                          var idOfst = charIDToTypeID( \"Ofst\" );

                              var desc5 = new ActionDescriptor();

                              var idHrzn = charIDToTypeID( \"Hrzn\" );

                              var idPxl = charIDToTypeID( \"#Pxl\" );

                              desc5.putUnitDouble( idHrzn, idPxl, 0 );

                              var idVrtc = charIDToTypeID( \"Vrtc\" );

                              var idPxl = charIDToTypeID( \"#Pxl\" );

                              desc5.putUnitDouble( idVrtc, idPxl, 0 );

                          var idOfst = charIDToTypeID( \"Ofst\" );

                          desc4.putObject( idOfst, idOfst, desc5 );

                          var idWdth = charIDToTypeID( \"Wdth\" );

                          var idPrc = charIDToTypeID( \"#Prc\" );

                          desc4.putUnitDouble( idWdth, idPrc, " & (imageScale) & " );

                          var idHght = charIDToTypeID( \"Hght\" );

                          var idPrc = charIDToTypeID( \"#Prc\" );

                          desc4.putUnitDouble( idHght, idPrc, " & (imageScale) & " );

                      executeAction( idPlc, desc4, DialogModes.NO );"

                        end tell

                        end tell

                      end place_image

                      • 8. Re: What sort of coordinates/units do the Action Manger's "Place" command use?
                        TomT-shirts Level 1

                        One more followup - while my thing with the selection was working fine, I was wrong about my constraints - sometimes I do have to place an image where the image bounds go past the canvas bounds. My method doesn't allow this, so I'm off to your method.

                         

                        Thanks! Great to have it working! Slightly slower than having it just place in the right place, but I'll take what works.

                        • 9. Re: What sort of coordinates/units do the Action Manger's "Place" command use?
                          pixxxel schubser MVP & Adobe Community Professional

                          You're welcome and nice to hear.

                           

                           

                          ------------------------------------------------------

                          But one note to your previous posting:

                          your line:

                          select region {{xCoordinate, yCoordinate}, {xCoordinate + 1, yCoordinate}, {xCoordinate, yCoordinate + 1}, {xCoordinate + 1, yCoordinate + 1}}

                          should be:

                          select region {{xCoordinate, yCoordinate}, {xCoordinate + 1, yCoordinate}, {xCoordinate + 1, yCoordinate + 1}, {xCoordinate, yCoordinate + 1}}

                           

                          Otherwise your selection is "overcrossed".

                           

                          And this method it's not the best. Why? Think casesensitiv.

                          Your selection has a dimension of one by one pixel. The middle is a half pixel. This is right, if the center of 8your placed) image also has the middle in x + (a half pixel). e.g. an image with 101 × 99 pixel

                          Do you understand?

                          What is the middle of an image with e.g. 102 × 100 pixel?

                          • 10. Re: What sort of coordinates/units do the Action Manger's "Place" command use?
                            TomT-shirts Level 1

                            Yes, I thought of that, and I could have done a two pixel square selection using all (Coordinate + 1) and (Coordinate - 1) values, so the center was the real center of the specified value. But the positioning we're doing isn't that critical... off by a few pixels won't make any difference.

                             

                            Since it turns out I sometimes need the placed art to be off the edge, your solution is better. I just have to go back and redo my math, because yours positions the art by the top left corner, and mine did it by the center. Easy enough though.

                             

                            -Tom.