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

Alinhamento de objetos pelo centro do objeto maior

Explorer ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

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

358

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 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
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 17, 2023 Jan 17, 2023

Copy link to clipboard

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

Votes

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

Copy link to clipboard

Copied

LATEST

Hi @Charu Rajput 

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?

Votes

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