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

Align NOT WORKING...(Script Illustrator)

Explorer ,
Jan 19, 2023 Jan 19, 2023

Copy link to clipboard

Copied

Hi

 

Why the cod below the object NOT ALIGN to objecto into layer "Cameron Esquerdo"?

 

var doc = app.activeDocument;
var filePath = "C:/Scripts/Registros/Centro.ai";
var layerName = "Cameron Esquerdo";

// Place the file into the active document
var importedFile = doc.placedItems.add();
importedFile.file = new File(filePath);

// Find the "Cameron Esquerdo" layer
var targetLayer = doc.layers.getByName(layerName);

var sel = doc.selection;
var rightmost;

// Find the object in the "Cameron Esquerdo" layer
for (var i = 0; i < sel.length; i++) {
if (sel[i].layer.name == "Cameron Esquerdo") {
rightmost = sel[i];
break;
}
}

// Add the imported file to the selection
sel.push(importedFile);

// Align the objects to the object in the "Cameron Esquerdo" layer
for (var i = 0; i < sel.length; i++) {
if (sel[i] != rightmost) {
var x = rightmost.left + (rightmost.width - sel[i].width) / 2;
var y = rightmost.top - (rightmost.height - sel[i].height) / 2;
sel[i].left = x;
sel[i].top = y;
}
}

TOPICS
Scripting

Views

246
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
Community Expert ,
Jan 19, 2023 Jan 19, 2023

Copy link to clipboard

Copied

LATEST

you can't compare objects like that, 

if (sel[i] != rightmost) {

 

you must compare a property value for example their "uuid"

rightmost = sel[i].uuid;

.

.

.

if (sel[i].uuid != rightmost) {

Votes

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