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

# Alinhamento de objetos pelo centro do objeto maior

Explorer ,
Jan 17, 2023 Jan 17, 2023

Copied

Olá... Saudações

No código abaixo, o alinhamento está acontecendo apenas na vertical e não alinha na horizontal ( ou vice-versa...hehehe) Alinhando o círculo branco com a barra.

Onde está o erro?

var doc = app.activeDocument;
var sel = doc.selection;
var biggest;

// Find the biggest object
for (var i = 0; i < sel.length; i++) {
if (!biggest || sel[i].width * sel[i].height > biggest.width * biggest.height) {
biggest = sel[i];
}
}

// Center the other objects to the biggest one
for (var i = 0; i < sel.length; i++) {
if (sel[i] != biggest) {
var x = biggest.left + (biggest.width - sel[i].width) / 2;
var y = biggest.top + (biggest.height - sel[i].height) / 100;
sel[i].left = x;
sel[i].top = y;

}
}

TOPICS
Scripting

Views

367

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 Expert , Jan 17, 2023 Jan 17, 2023

Hi,

When you are calculating the y, why are you diving by 100? Try following version

``````var doc = app.activeDocument;
var sel = doc.selection;
var biggest;

// Find the biggest object
for (var i = 0; i < sel.length; i++) {
if (!biggest || sel[i].width * sel[i].height > biggest.width * biggest.height) {
biggest = sel[i];
}
}

// Center the other objects to the biggest one
for (var i = 0; i < sel.length; i++) {
if (sel[i] != biggest) {
var x = biggest.left + (biggest.width``````
...

2 Replies 2
Community Expert ,
Jan 17, 2023 Jan 17, 2023

Copied

Hi,

When you are calculating the y, why are you diving by 100? Try following version

``````var doc = app.activeDocument;
var sel = doc.selection;
var biggest;

// Find the biggest object
for (var i = 0; i < sel.length; i++) {
if (!biggest || sel[i].width * sel[i].height > biggest.width * biggest.height) {
biggest = sel[i];
}
}

// Center the other objects to the biggest one
for (var i = 0; i < sel.length; i++) {
if (sel[i] != biggest) {
var x = biggest.left + (biggest.width - sel[i].width) / 2;
var y = biggest.top - (biggest.height - sel[i].height) / 2;
sel[i].left = x;
sel[i].top = y;

}
}``````

Best regards

Report

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

Copied

LATEST

Thanks for your help. Its work perfectly.

I want make de align for a object into layer "Cameron Right".

Could you help me one more time?