Help with script to change fill and stroke colors
I am new to scripting and found some code I could get to work on all my layers:
var doc = app.activeDocument;
var swatch = app.activeDocument.swatches.getByName('Birch Product');
var stroke = app.activeDocument.swatches.getByName('New Pattern Swatch 9');
for ( i = 0; i <doc.pathItems.length; i++ ) {
pathArt = doc.pathItems[i];
pathArt.strokeWidth = 2;
pathArt.strokeColor = stroke.color;
pathArt.fillColor = swatch.color;
}
I would like to apply this to only a specific layer instead of all layers. Tried the code below but it did not work; nothing happened. What do I need to do to get it to change just that layer. I also tried "PageItems", but that didn't work either.
var greenLayer = app.activeDocument.layers.getByName("GREEN");
var swatch = app.activeDocument.swatches.getByName('Birch Product');
var stroke = app.activeDocument.swatches.getByName('New Pattern Swatch 9');
for ( i = 0; i <greenLayer.pathItems.length; i++ ) {
pathArt = greenLayer.pathItems[i];
pathArt.strokeWidth = 2;
pathArt.strokeColor = stroke.color;
pathArt.fillColor = swatch.color;
}
