1 Reply Latest reply on Jan 17, 2015 8:09 AM by JJMack

    Position layer in the centre of document

    Mattmcquiff Level 1

      I'm trying to copy a document from one open document to another which I have achieved, but how can I position it in the centre of the new document?

      This is what I am using at the moment,

       

      tell application id "com.adobe.photoshop"

        set textName to name of current document

        set MainDocument to current document

        set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "_"}

        set imageDoc to first text item of textName

        set SecondaryDoc to document (imageDoc & ".PSD")

        log SecondaryDoc

        log MainDocument

       

        set current document to SecondaryDoc

        duplicate layer "Main Image" of layer set "Dodge and Burn" of SecondaryDoc to before layer "Main Image" of MainDocument

        set current document to MainDocument

       

       

       

       

      end tell

        • 1. Re: Position layer in the centre of document
          JJMack Most Valuable Participant

          Do a select all and use action manager code to align the layer to the horizontal and vertical center of the selection. Javascript code posted by Paul.

          function align(method) {
            var desc = new ActionDescriptor();
            var ref = new ActionReference();
            ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
            desc.putReference( charIDToTypeID( "null" ), ref );
            desc.putEnumerated( charIDToTypeID( "Usng" ), charIDToTypeID( "ADSt" ), charIDToTypeID( method ) );
            try{
            executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );
            }catch(e){}
          }
          
          
          
          

           

           

          Useage like the 9 positions in a tick tack toe board. Yours would be case 5...

          switch (Position){
          case 1 : align('AdLf'); align('AdTp'); break;
          case 2 : align('AdCH'); align('AdTp'); break;
          case 3 : align('AdRg'); align('AdTp'); break;
          case 4 : align('AdLf'); align('AdCV'); break;
          case 5 : align('AdCH'); align('AdCV'); break;
          case 6 : align('AdRg'); align('AdCV'); break;
          case 7 : align('AdLf'); align('AdBt'); break;
          case 8 : align('AdCH'); align('AdBt'); break;
          case 9 : align('AdRg'); align('AdBt'); break;