Skip to main content
Known Participant
February 22, 2019
Resuelto

Change position of layer to top left of the art board using script

  • February 22, 2019
  • 2 respuestas
  • 1855 visualizaciones

Hi guys, i just want to ask how to change the position of the layer to top left in the art board using script. I have a code here that i found through searching but it will only change the position to the center of the art board and i tried changing it to make the position to top left but i cant seem to make it right. can you guys please help me. it would be a huge help, The code is below.

var docRef = app.activeDocument;

   with (docRef) {

   rulerOrigin = [0,0];

   var docVB = visibleBounds;

 

   var transX = (width / 2) - ((docVB[0] + docVB[2]) / 2);

   var transY = (height / 2) - ((docVB[1] + docVB[3]) / 2);

  

   for (var i = 0; i < layers.length; i++) {

   for (var j = 0; j < layers.pageItems.length;j++) {

   layers.pageItems.translate(transX, transY);

  }

  }

  }

Este tema ha sido cerrado para respuestas.
Mejor respuesta de Silly-V

If the rulerOrigin works and makes your top-left of the artboard at [0,0] then without translation it may be possible to simply set the position of the art to the coordinates explicitly:

layers.pageItems.top = 0;

layers.pageItems.left = 0;

Try to see what this would do?

2 respuestas

renél80416020
Inspiring
February 22, 2019

Bonjour à tous,

Si j'ai bien compris la demande de https://forums.adobe.com/people/john+jayd21181923

ce script devrait convenir.

    var docRef = app.activeDocument;

    with (docRef) {

      var rect = artboards[0].artboardRect;

      var docVB = visibleBounds;

      var transX = rect[0]-docVB[0];

      var transY = rect[1]-docVB[1];

        for (var j = 0; j < pageItems.length;j++) {

          pageItems.translate(transX,transY);

        }

    }

Silly-V
Silly-VRespuesta
Legend
February 22, 2019

If the rulerOrigin works and makes your top-left of the artboard at [0,0] then without translation it may be possible to simply set the position of the art to the coordinates explicitly:

layers.pageItems.top = 0;

layers.pageItems.left = 0;

Try to see what this would do?

Known Participant
February 26, 2019

thanks! that helps me a lot. do you also know how to make the layers but not the page items to be position to top left i tried this but it wont work. sorry i'm new to javascript.

for(i = 0; i < layers.length; i++){
          layers.top = 0;

          layers.left = 0;

}

CarlosCanto
Community Expert
Community Expert
February 26, 2019

layers are containers, there's no position for them. You position the items inside layers.