Aya Moyal
Aya Moyal

Reputation: 1

How can I align a layer to another one?

I am trying to align a layer to top and left of another layer. I found code that does the align, but the selection part I changed does not work.

How do I set the selection to a specific layer I have?

Doc.selection.select(ImgLocation);
Doc.activeLayer = layer;

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('AdLf'));
desc.putEnumerated(charIDToTypeID("Usng"), charIDToTypeID("ADSt"), charIDToTypeID('AdTp'));
try {
  executeAction(charIDToTypeID("Algn"), desc, DialogModes.NO);
} catch (e) {}

Doc.selection.deselect();

ImgLocation is a ArtLayer object I want to align to; layer is the layer i want to do the alignment function on.

Upvotes: 0

Views: 22

Answers (1)

Ghoul Fool
Ghoul Fool

Reputation: 6967

Aligning layers is straight forward only complicated by which way you want to align things.

function align_it(charID, bool)
{

  //       phEnumADSTops -> 1097094256 -> "AdTp"  ADSTops
  //   phEnumADSCentersV -> 1097089878 -> "AdCV"  ADSCentersV
  //    phEnumADSBottoms -> 1097089652 -> "AdBt"  ADSBottoms

  //      phEnumADSLefts -> 1097092198 -> "AdLf"  ADSLefts
  //   phEnumADSCentersH -> 1097089864 -> "AdCH"  ADSCentersH
  //     phEnumADSRights -> 1097093735 -> "AdRg"  ADSRights


  //   phEnumADSVertical -> 1097094770 -> "AdVr"  ADSVertical
  // phEnumADSHorizontal -> 1097091186 -> "AdHr"  ADSHorizontal


  if (charID == "") return;
  var alignID = "Algn";
  if (bool == false) alignID = "Dstr";

   // =======================================================
   var idAlgn = charIDToTypeID( alignID );
   var desc125 = new ActionDescriptor();
   var idnull = charIDToTypeID( "null" );
   var ref34 = new ActionReference();
   var idLyr = charIDToTypeID( "Lyr " );
   var idOrdn = charIDToTypeID( "Ordn" );
   var idTrgt = charIDToTypeID( "Trgt" );
   ref34.putEnumerated( idLyr, idOrdn, idTrgt );
   desc125.putReference( idnull, ref34 );
   var idUsng = charIDToTypeID( "Usng" );
   var idADSt = charIDToTypeID( "ADSt" ); // alignDistributeSelector
   var idAdCV = charIDToTypeID( charID ); // character ID
   desc125.putEnumerated( idUsng, idADSt, idAdCV );
   executeAction( idAlgn, desc125, DialogModes.NO );
}

You can see from the comments the alignment type, code, four letter code and then alignment type. By setting the boolean it switches from align to distribute.

As for the layers, I think it relies on having more than one layer selected. How do you get selected layers? You can find out more as that question has been already answered.

Upvotes: 0

Related Questions