Photoshop scripting: Move an image to position x,y

Max Kielland picture Max Kielland · Aug 22, 2012 · Viewed 15.4k times · Source

I have an active ArtLayer referenced by the variable NewLayer that I want to move to the absolute position x,y in the canvas.

I have been googling for a couple of hours now without any results. Can some one please give an example?

// Thanks.

Answer

Max Kielland picture Max Kielland · Aug 22, 2012

After some more API reading and searching I came to the conclusion that it is only possible to move a layer with delta move.

I wrote this little function to position a layer at an absolute position. Hope this is helpful to the next reader with the same question...

//******************************************
// MOVE LAYER TO
// Author: Max Kielland
//
// Moves layer fLayer to the absolute
// position fX,fY. The unit of fX and fY are
// the same as the ruler setting. 

function MoveLayerTo(fLayer,fX,fY) {

  var Position = fLayer.bounds;
  Position[0] = fX - Position[0];
  Position[1] = fY - Position[1];

  fLayer.translate(-Position[0],-Position[1]);
}