Skip to main content
swapnilwajpe
Participant
January 14, 2016
Answered

Selecting multiple layers and aligning them via a script

  • January 14, 2016
  • 2 replies
  • 4207 views

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

This topic has been closed for replies.
Correct answer JJMack

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.


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

};

2 replies

c.pfaffenbichler
Community Expert
Community Expert
January 14, 2016

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?

JJMack
Community Expert
Community Expert
January 14, 2016

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


JJMack
swapnilwajpe
Participant
January 14, 2016

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.

JJMack
Community Expert
Community Expert
January 14, 2016

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

JJMack