Skip to main content
Participant
January 13, 2023
Answered

Adober Illustrator Script

  • January 13, 2023
  • 1 reply
  • 447 views

I have a script that's meant to collect objects of similar fill color and place them in seperate layers, then name the layer by the name of the spot color of the objects, then order the layers alphanumerically. It runs sometimes, while other times Illustrator stops responding halfway through creating layers. Can anyone suggest what may be the problem?

 

I run this once I have used Edit Colors to make every color in my file a Spot Color and I get no error message when it doesn't work. With some files it works, but with others, it doesn't.

Please let me know any advice you may have!

 

var acl = app.activeDocument.activeLayer;
while (acl.pathItems.length != 0) {
    try {
        var layer = app.activeDocument.layers.add();
        layer.name = acl.pathItems[0].fillColor.spot.name;
        activeDocument.selection = acl.pathItems[0];
        app.executeMenuCommand("Find Fill & Stroke menu item");
        for (var j = 0; j < activeDocument.selection.length; j++) {
            activeDocument.selection[j].move(layer, ElementPlacement.PLACEATBEGINNING);
        }
        // app.executeMenuCommand("compoundPath");
    } catch (e) {
        continue;
    }
};
if (activeDocument.selection.length) {
    app.activeDocument.activeLayer.name = activeDocument.selection[0].fillColor.spot.name
}

var doc = app.activeDocument;
var layers = doc.layers;
var layersArray = [];

// Push all layers into an array
for (var i = 0; i < layers.length; i++) {
    layersArray.push(layers[i]);
}

// Sort the array by layer name
layersArray.sort(function(a, b) {
    var colorA = a.name.split(" ")[0].split("=")[1];
    var colorB = b.name.split(" ")[0].split("=")[1];
    return colorB - colorA;
});


// Add the sorted layers back to the document
for (var i = 0; i < layersArray.length; i++) {
    layersArray[i].zOrder(ZOrderMethod.BRINGTOFRONT);
}

 

 

This topic has been closed for replies.
Correct answer max231231

PROBLEM SOLVED---- So in my swatch library, I had pure black(R=0 G=0 B=0) and Pure white (R=255 G=255 B=255) and the script wasn't recognizing these as spot colors for some reason. My solution was to the pure black and pure white swatches so that they were slightly lighter and darker respectively so that Adobe script recognized them as spot colors.

1 reply

max231231AuthorCorrect answer
Participant
January 13, 2023

PROBLEM SOLVED---- So in my swatch library, I had pure black(R=0 G=0 B=0) and Pure white (R=255 G=255 B=255) and the script wasn't recognizing these as spot colors for some reason. My solution was to the pure black and pure white swatches so that they were slightly lighter and darker respectively so that Adobe script recognized them as spot colors.

max231231Author
Participant
January 13, 2023

.....my solution was to *change* the pure black and pure white swatches....