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