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

Alinhamento pelo centro na vertical

Explorer ,
Jan 20, 2023 Jan 20, 2023

Copy link to clipboard

Copied

Hi

 

In the code below the object of the chamber "Cameron Right" shifts vertically but does not center on the artboart. What's wrong ?

 

// Get the active document
var doc = app.activeDocument;

// Get the "Cameron Direito" layer
var layer = doc.layers.getByName("Cameron Direito");

// Get the first item in the layer
var item = layer.pageItems[0];

// Get the bounds of the artboard
var artboardBounds = doc.artboards[0].artboardRect;

// Calculate the center of the artboard
var centerY = (artboardBounds[3] - artboardBounds[1]) / 2 + artboardBounds[1];

// Position the item at the center of the artboard
item.position = [item.position[0], centerY];

TOPICS
Scripting

Views

229

Likes

Translate

Translate

Report

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

Community Expert , Jan 23, 2023 Jan 23, 2023

Replace the last line of your code with:

item.position = [item.position[0], centerY+item.height/2];

Likes

Translate

Translate
Explorer ,
Jan 20, 2023 Jan 20, 2023

Copy link to clipboard

Copied

In the code below the object of the layer "Cameron Direito" shifts vertically but does not center on the artboart. What's wrong with you?

Likes

Translate

Translate

Report

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 ,
Jan 20, 2023 Jan 20, 2023

Copy link to clipboard

Copied

quote

... What's wrong with you?


By @Julio Ricardo

 

That seems to be a translation issue - right?

 

And the answer is:

Nothing is wrong with your code. Your snippet works as expected.

 

Unforturnately you forgot to calculate the middle of your item. "Position" always set/get the top left coordinate.

 

That's all.

 

Have fun

😉

 

Likes

Translate

Translate

Report

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
Explorer ,
Jan 23, 2023 Jan 23, 2023

Copy link to clipboard

Copied

Hi

 

Could you show me ?

Likes

Translate

Translate

Report

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 ,
Jan 23, 2023 Jan 23, 2023

Copy link to clipboard

Copied

Replace the last line of your code with:

item.position = [item.position[0], centerY+item.height/2];

Likes

Translate

Translate

Report

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
Adobe Employee ,
Jan 23, 2023 Jan 23, 2023

Copy link to clipboard

Copied

Hello @Julio Ricardo,

 

Thanks for reaching out. I hope the suggestions shared by pixxxelschubser helped resolve the trouble you were having with your script. Feel free to reach out if you have more questions or need assistance. We'd be happy to help.

Thanks,

Anubhav

Likes

Translate

Translate

Report

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
Explorer ,
Jan 26, 2023 Jan 26, 2023

Copy link to clipboard

Copied

LATEST

Thank you so much ! 

Likes

Translate

Translate

Report

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