Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Feb 22, 2019 Feb 22, 2019

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

  }

  }

  }

TOPICS
Scripting
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Feb 22, 2019 Feb 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?

Translate
Adobe
Valorous Hero ,
Feb 22, 2019 Feb 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 25, 2019 Feb 25, 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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 26, 2019 Feb 26, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 26, 2019 Feb 26, 2019
LATEST

okay, thanks a lot.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Feb 22, 2019 Feb 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);

        }

    }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines