Skip to main content
matthieu_8244
Participant
March 17, 2026
Question

Behavioral differences between MacOS versions for a resizing script (Illustrator 30.2.1)

  • March 17, 2026
  • 3 replies
  • 131 views

Hello,

I have an extendscript that imports a file and resizes that import based on the value in /tmp/valeurTauxReduc.txt (for example 80)

app.executeMenuCommand('preview');
var docRef = activeDocument;
var lireTauxReduc = new File ("/tmp/valeurTauxReduc.txt");
lireTauxReduc.encoding = "UTF8";
lireTauxReduc.lineFeed = "unix";
lireTauxReduc.open("r");
var resultlireTauxReduc = lireTauxReduc.readln();
numbReduc = parseInt(resultlireTauxReduc);
redraw();

var saveFileTempo = new File("path/to/file.pdf");
fichierPdf.copy(saveFileTempo);
docRef.placedItems[0].relink(saveFileTempo); // Importe le fichier
// Incorporer l'image importée
docRef.placedItems[0].embed();
// Mise à l'échelle du décor uniquement
if (lireTauxReduc.exists == true){
docRef.groupItems[0].resize(numbReduc, numbReduc, true, false, false, false, 100, Transformation.CENTER);
}
redraw();

It works flawlessly on my Mac (Sonoma 14.6.1) but for some reason doesn’t do the resize() on a more recent one (Tahoe 26.3.1).
I’ve tried debuging it in many ways (alerts, try-catches, using the debug extension for vs code) but to no avail, the script does the resize but the items are not resized.

My last attempt was to create a cube and resize it which works on both computers

// Créer un cube rouge et le redimensionner à 50%
var redCubeLayer = docRef.layers.add();
redCubeLayer.name = "RedCube";
var cubeSize = 100; // Taille du cube en points
var redCube = redCubeLayer.pathItems.rectangle(0, 0, cubeSize, cubeSize);
var redColor = new CMYKColor();
redColor.cyan = 0;
redColor.magenta = 100;
redColor.yellow = 100;
redColor.black = 0;
redCube.filled = true;
redCube.fillColor = redColor;
redCube.stroked = false;
// Redimensionner le cube à 50%
redCube.resize(80, 80, true, false, false, false, 100, Transformation.CENTER);
redraw();

Even with this discovery i have yet to grasp the answer thus why I am turning to the community for enlightenment

3 replies

Alexandre Becquet
Community Expert
Community Expert
March 24, 2026

Tu peux écrire en Français si ut veux on un bouton de traduction ;) mais moi ça va !!!

J’ai demandé à Claude IA pour le code et il me propose ça que je n’ai pas encore testé. Dis moi si le problème est réglé .
Explication : 
Quand embed() est appelé, Illustrator convertit le placedItem en groupe natif. Cela réindexe groupItems[] — sur Sonoma ça passait, sur Tahoe le comportement est plus strict. groupItems[0] pointe désormais sur l'objet fraîchement embarqué, pas sur ton décor.

Proposition de correction

app.executeMenuCommand('preview');
var docRef = activeDocument;

// --- Lecture sécurisée du taux ---
var numbReduc = 100;
var lireTauxReduc = new File("/tmp/valeurTauxReduc.txt");

if (lireTauxReduc.exists) {
    lireTauxReduc.encoding = "UTF8";
    lireTauxReduc.lineFeed = "unix";
    lireTauxReduc.open("r");
    var raw = lireTauxReduc.readln();
    lireTauxReduc.close();
    
    // ✅ Nettoyage du string avant parseInt
    var parsed = parseInt(raw.replace(/\s+/g, ""), 10);
    if (!isNaN(parsed) && parsed > 0) numbReduc = parsed;
}

// ✅ Capturer la référence au groupe AVANT toute modification structurelle
var decorGroup = null;
if (docRef.groupItems.length > 0) {
    decorGroup = docRef.groupItems[0]; // référence stable capturée ici
}

redraw();

// --- Remplacement du fichier lié ---
var fichierPdf   = new File("/chemin/vers/source.pdf");
var saveFileTempo = new File(Folder.temp + "/fichier_tempo.pdf");

if (fichierPdf.exists && docRef.placedItems.length > 0) {
    fichierPdf.copy(saveFileTempo);
    docRef.placedItems[0].relink(saveFileTempo);
    docRef.placedItems[0].embed();
    // ← groupItems est réindexé ICI, mais decorGroup est déjà sauvegardé
}

// --- Mise à l'échelle du décor via référence stable ---
if (decorGroup !== null) {
    try {
        decorGroup.resize(
            numbReduc, numbReduc,
            true, false, false, false, 100,
            Transformation.CENTER
        );
    } catch(e) {
        alert("Resize échoué : " + e.message + "\nnumbReduc = " + numbReduc);
    }
}

redraw();

Alexandre Becquet
Community Expert
Community Expert
March 23, 2026

Hello, if you send me the script i can test on my Mac ;) and find the issue ;)

CarlosCanto
Community Expert
Community Expert
March 23, 2026

I used this simplified version for testing.

I open a blank ai file, placed a pdf before running the script

I also used another pdf that the script will use to replace the pdf on canvas. Edit the script to use your own pdf file path

var docRef = activeDocument;

numbReduc = 80
app.redraw();

var saveFileTempo = new File("c:/files/relinkTest.pdf");

docRef.placedItems[0].relink(saveFileTempo); // Importe le fichier
// Incorporer l'image importée
docRef.placedItems[0].embed();
// Mise à l'échelle du décor uniquement
app.redraw();
docRef.groupItems[0].resize(numbReduc, numbReduc, true, false, false, false, 100, Transformation.CENTER);

app.redraw();

 

CarlosCanto
Community Expert
Community Expert
March 22, 2026

I don’t have a mac to test,

have you tried placing a redraw() right after embedding?