Skip to main content
Inspiring
Jan 19, 2023 1:24 PM UTC
Question

Align NOT WORKING...(Script Illustrator)

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

This topic is closed to new replies. Start a new post to keep the conversation going.

1 reply

CarlosCanto
Community Expert
Community Expert
Jan 19, 2023 4:46 PM UTC

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

Translate