Skip to main content
Participant
January 12, 2023
Answered

I am looking for a script to help me with a common daily task that I do in illustrator 2022

  • January 12, 2023
  • 1 reply
  • 415 views

https://www.dropbox.com/sh/ywb2aizjwyjpzcg/AAAl846MJlQzGemYyWFfcfEAa?dl=0

Above is a dropbox link of the eps keyline file and the script i got off a different Adobe forum, I have made some adjustments to the script to suit my keyline colours but it is still giving me errors. I am looking to run a script that creates new layers in my opened illustrator keyline file and grabs the spot colours and the CMYK Colours onto their own seperate layers eg below.

I would like the script to create the below layers for the relevant colours

Layer Name = Cut for the spot Colour "Artios_Cut"

Layer Name = Crease for the spot Colour "Artios_Crease"

Layer Name = Dimensions for the spot Colour "Artios_Dimensions and text"

All the rest of the artwork can be left on a Layer called "Annotation"

 

I would really love a solution to this daily task so any help would be really appreciated.

Graham

This topic has been closed for replies.
Correct answer femkeblanco

This has not been rigorously tested,  but it should

  1. create a layer (if one does not pre-exist) for every spot color swatch; and
  2. move items with the same spot or CMYK color to the layer in question.  (Items with no corresponding spot color swatch stay where they are.)

 

app.selection = null;
var doc = app.activeDocument;
for (var i = 2; i < doc.swatches.length; i++) {
    if (doc.swatches[i].color.typename == "SpotColor") {
        try {
            var layer1 = doc.layers[doc.swatches[i].name];
        } catch(e) {
            var layer1 = doc.layers.add();
            layer1.name = doc.swatches[i].name;
        } finally {
            doc.defaultFillColor = doc.swatches[i].color.spot.color;
            move("Find Fill Color menu item");
            doc.defaultFillColor = doc.swatches[i].color;
            move("Find Fill Color menu item");
            doc.defaultStrokeColor = doc.swatches[i].color.spot.color;
            move("Find Fill Color menu item");
            doc.defaultStrokeColor = doc.swatches[i].color;
            move("Find Stroke Color menu item");
        }
    }
}
function move(command) {
    app.executeMenuCommand(command);
    for (var j = 0; j < doc.selection.length; j++) {
        doc.selection[j].moveToEnd(layer1);
    }
    app.selection = null;
}​

 

 

1 reply

femkeblanco
Legend
January 14, 2023

I suspect you haven't gotten replies because your post is unclear.  You talk about "grab(bing) ... colours ... onto ... layers".  What I suspect you mean is that you want to move same-color items onto their own layer.  Is this the case? 

Participant
January 17, 2023

Hi femkeblanco,

Yes by grab I mean "select and move". I suppose the essence of what I need is a script that creates the specific layers I have said in the previous post, ie - "Cut" and if the same script could select a specific spot colour stroke called "Artios_Cut" and move it to this layer.

femkeblanco
femkeblancoCorrect answer
Legend
January 17, 2023

This has not been rigorously tested,  but it should

  1. create a layer (if one does not pre-exist) for every spot color swatch; and
  2. move items with the same spot or CMYK color to the layer in question.  (Items with no corresponding spot color swatch stay where they are.)

 

app.selection = null;
var doc = app.activeDocument;
for (var i = 2; i < doc.swatches.length; i++) {
    if (doc.swatches[i].color.typename == "SpotColor") {
        try {
            var layer1 = doc.layers[doc.swatches[i].name];
        } catch(e) {
            var layer1 = doc.layers.add();
            layer1.name = doc.swatches[i].name;
        } finally {
            doc.defaultFillColor = doc.swatches[i].color.spot.color;
            move("Find Fill Color menu item");
            doc.defaultFillColor = doc.swatches[i].color;
            move("Find Fill Color menu item");
            doc.defaultStrokeColor = doc.swatches[i].color.spot.color;
            move("Find Fill Color menu item");
            doc.defaultStrokeColor = doc.swatches[i].color;
            move("Find Stroke Color menu item");
        }
    }
}
function move(command) {
    app.executeMenuCommand(command);
    for (var j = 0; j < doc.selection.length; j++) {
        doc.selection[j].moveToEnd(layer1);
    }
    app.selection = null;
}​