Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

applying a swatch to a pathitem

Engaged ,
Oct 27, 2014 Oct 27, 2014

I am trying to apply a swatch to all pathItems on a certain layer. I have the code written to access the layer I want but I am not sure how to apply a specific swatch name to the pathItems on the layer that I want. In my code if the pathItem is on a layer named "651(Highways)" I want the swatch in my document labeled "651 (Blue Gray)" to be applied to all those pathItems.

Anyone help me out with that? I am sure it is simple but I have never done it before and not much luck Google'n it.

Here is my code....

#target illustrator

var doc = app.activeDocument;

var allLayers = doc.layers;

var allLines = doc.pathItems;

var allSwatches = doc.swatches;

// CHECK TO SEE WHAT LAYER PATH ITEMS ARE ON

for (var i = allLines.length-1; i >= 0; i--){

  if (allLines.layer == "[Layer Rails/Feather Bars]"){

  allLines.filled = false;

  lineFormat();

  blackStroke();

  allLines.strokeWidth = 2.0;

  }

  else if (allLines.layer == "[Layer 651 (Highways)]"){

  lineFormat();

  allLines.strokeWidth = 1.1;

  }

else {

  //alert("Found line on " + allLines.layer);

  }

}

function lineFormat(){

  allLines.filled = false;

  allLines.strokeWidth = 1.6;

  allLines.strokeJoin = StrokeJoin.MITERENDJOIN;

  allLines.strokeCap = StrokeCap.BUTTENDCAP;

  }

function blackStroke(){

  var blackLine = new GrayColor();

  blackLine.gray = 100;

  allLines.stroked = true;

  allLines.strokeColor = blackLine;

  }

TOPICS
Scripting
785
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 27, 2014 Oct 27, 2014

try

allLines.fillColor = allSwatches['651 (Blue Gray)'].color;

Translate
Adobe
Community Expert ,
Oct 27, 2014 Oct 27, 2014

try

allLines.fillColor = allSwatches['651 (Blue Gray)'].color;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 27, 2014 Oct 27, 2014

That worked! Only thing I changed was .fillColor to .strokeColor

  1. allLines.strokeColor = allSwatches['651 (Blue Gray)'].color;

THANK YOU CARLOS!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 27, 2014 Oct 27, 2014
LATEST

Great, you're welcome

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines