Skip to main content
subieguy2
Inspiring
August 20, 2009
Question

Script to select same stroke color and apply a new swatch...

  • August 20, 2009
  • 1 reply
  • 1456 views

I am trying to write a script that will select a line based on a swatch name, apply a new swatch, set the stroke, dash and miter of the line...and then create a new layer, change then name of the layer, and then move the selected items to the newly created layer.

All I could seem to accomplish was renaming a swatch.

var swatchName = app.activeDocument.swatches;

if (swatchName.length > 0) {
    for (i=0; i < swatchName.length; i++){  
        changeName(swatchName);
    }
}

function changeName(swatchObject){
                 if (swatchObject.name == "PANTONE Orange 021 C"){                     
                    swatchObject.name = "021 (Orange)";
               }
                if (swatchObject.name == "PANTONE Red 032 C"){                     
                    swatchObject.name = "032 (Red)";

}

So the goal of what I would like it to do is look for all paths with the stroke color set to "PANTONE Orange 021 C" then have it change the swatch name to "021 (Orange)". After that apply the stroke, dash and miter. Create a new layer named "021 (Orange)". Then send all of the selected lines to that layer.

PLEASE HELP AS I HAVE 200+ files to do this task to. Using a windows machine with CS3. Trying to write in javascript.

This topic has been closed for replies.

1 reply

Muppet_Mark-QAl63s
Inspiring
August 8, 2010

This would be the way to rename 2 existing swatches… The GUI pallet can be a little sticky in updating but it works…

#target illustrator var docRef = app.activeDocument; var a = docRef.swatches.getByName('PANTONE Orange 021 C'); a.name = '021 (Orange)'; var b = docRef.swatches.getByName('PANTONE Red 032 C'); b.name = '032 (Red)'; redraw();

My mistake… Looks like this Jive stuff gave you an unwanted bump from nowhere? Didn't look at the date…