8 Replies Latest reply on Jan 15, 2016 5:28 AM by JJMack

    Selecting multiple layers and aligning them via a script

    swapnilw27343394 Level 1

      snip_20160114102022.png

      I have the following layer setup and here is what I want to do via a script

       

      1) Select Layer 1 and Layer 0

      2) Align Layer 0 to left of the canvas

      3) Select Layer 1 and Layer 0 copy

      4) Align Layer 0 copy to the right of the canvas

       

      Is this even possible via script? Document sizes vary

        • 1. Re: Selecting multiple layers and aligning them via a script
          JJMack Most Valuable Participant

          You use align layers to selection. Exapmles scripts in my package,

           

          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

          • 2. Re: Selecting multiple layers and aligning them via a script
            c.pfaffenbichler Level 9

            1) Select Layer 1 and Layer 0

            2) Align Layer 0 to left of the canvas

            3) Select Layer 1 and Layer 0 copy

            Why do you want to select Layer 1 at all?

            • 3. Re: Selecting multiple layers and aligning them via a script
              JJMack Most Valuable Participant

              It easy to do manually you would automat it the same wat with avd action or script.

              With the move tool active you select all to activate the alignment icone int the tool option bar

              Targer one layer and use the align layers to the selection left side

              Target second layer and use the align layers to the selection right side


              you can also write a script to expand the canvas to house a layers content and align the layer to the added canvas. for example

              http://www.mouseprints.net/old/dpr/pasteClipboard.jsx


              Capture.jpg

              • 4. Re: Selecting multiple layers and aligning them via a script
                swapnilw27343394 Level 1

                @c.pfaffenbichler

                 

                That's how I manually do it, so wanted to replicate the steps in script. If it is possible to align the layers without selecting Layer 1 that will be great, I am open to suggestions

                • 5. Re: Selecting multiple layers and aligning them via a script
                  swapnilw27343394 Level 1

                  Thanks for your replies @JJMack but I want to do it via script and strictly via script no manual no actions, just script. Actually its just a part of my script. My rest of the steps are done, just stuck on this alignment part.

                  • 6. Re: Selecting multiple layers and aligning them via a script
                    JJMack Most Valuable Participant

                    If you look at the script I posted it does the select all and the two align steps to allign the current layer.  All the four charter alignment id are listed in the  code. all you need do is target the layer you want to align. it should look something like this

                     

                    var savedActiveLayer = app.activeDocument.activeLayer;  // save current adtive layer

                    app.activeDocument.selection.selectAll();                          // select all

                    // Left('AdLf'); Right('AdRg'); Top('AdTp'); Bottom('AdBt'); Center Horizontal('AdCH'); Center Vertical('AdCV');

                    add code to target layer 0                                                  // activeDocument.activeLayer = layers 0

                    align("AdLf");                                                                    // Align to selection Left Side

                    add code to target layer 0 copy                                          // activeDocument.activeLayer = layers 0 copy 

                    align("AdRg");                                                                  //Align to selection Right  Side

                    app.activeDocument.selection.deselect();                           // deselect

                    app.activeDocument.activeLayer = savedActiveLayer;        // restore current layer

                    //////////////////////////////////////////////////

                    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 ) );

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

                    };

                    • 7. Re: Selecting multiple layers and aligning them via a script
                      swapnilw27343394 Level 1

                      JJMack

                      This worked, thank you so much.

                       

                      Though I have no idea what the "function align(method) {}" code does, I understood the code above that.

                       

                      Thank you once again

                      • 8. Re: Selecting multiple layers and aligning them via a script
                        JJMack Most Valuable Participant

                        That is Action Manager code recorded by Adobe ScriptListener Plug-in for Photoshop actions step for menu Layer>Align Layers to Seletion>alignement

                        The alignment is passed.