Beenden
  • Globale Community
    • Sprache:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티

Illustrator Script Error at Line 20 with Compound Paths

Neu hier ,
Sep 24, 2025 Sep 24, 2025

Hi, so I ran into a blocking error today while running RandomSwatchesFill.js, a well-known script for Adobe Illustrator. The goal is simple: fill the selected shapes with a random color from the swatches I have selected. It worked perfectly yesterday, but today Illustrator suddenly stops with an error on line 20. Nothing has changed in my Illustrator setup between then and now, which makes the issue even more puzzling.

Screenshot_50.png

The Script:

 

 
mySelection = app.activeDocument.selection;
myDoc = app.activeDocument;
if (mySelection instanceof Array)
{
    selSwatches = myDoc.swatches.getSelected();
    
    if(selSwatches.length != 0)
        for (i=0; i<mySelection.length; i++)
        {
            if(mySelection[i].typename == "PathItem" || mySelection[i].typename == "CompoundPathItem")
            {
                selItem = mySelection[i];
                selItem.filled = true;

                swatchIndex = Math.round( Math.random() * (selSwatches.length - 1 ));
                
                if(selItem.typename == "PathItem")
                    selItem.fillColor = selSwatches[swatchIndex].color;
                else
                    selItem.pathItems[0].fillColor = selSwatches[swatchIndex].color;
                
            }
        }
}

 

Illustrator reports the error at line 20:

 

 
selItem.pathItems[0].fillColor = selSwatches[swatchIndex].color;

 

Anyway if you can help me resolve this problem that would be great

THEMEN
Fehler , Zeichnen und gestalten , Skripterstellung
66
Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Adobe
Enthusiast ,
Sep 24, 2025 Sep 24, 2025

How are these objects made? If you call the Release Compound Path, will there be groups of objects? If there are groups, the script cannot get the first path selItem.pathItems[0] inside the compound path.

 

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines
Community Expert ,
Sep 24, 2025 Sep 24, 2025
AKTUELL

insert 

alert(selItem.typename);

 

before the error line to find out what type of object is causing the error and we go from there

 

[edit] it will always be "compound path" duh! ignore my comment, follow Sergey comments

Übersetzen
Melden
Community-Richtlinien
Seien Sie freundlich und respektvoll, geben Sie die ursprüngliche Quelle der Inhalte an und suchen Sie vor dem Absenden Ihres Beitrags nach Duplikaten. Weitere Informationen
community guidelines