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

Compare pathItem.fillColor to no fill

Engaged ,
Oct 29, 2014 Oct 29, 2014

Copy link to clipboard

Copied

I am running a simple script that checks a certain layer for any circle that is not colored properly.

I have 4 circles and 1 line on my test document. I am checking to see if any items on a specific layer "Circles" exist.

Capture.JPG

Two circles filled and stroked correctly and two incorrect. Then a line (between the 2 red circles) is NOT supposed to be on this layer and has a fill color of None.

When I run the following script I get the output that there are 3 correct circles and 2 incorrect circles. The line between the red circles is coming in as correct. Any ideas why?

#target illustrator

var doc = app.activeDocument;

var allLayers = doc.layers;

var noColor = new NoColor();

var allLines = doc.pathItems;

var correct = 0;

var incorrect = 0;

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

  if (allLines.layer == "[Layer Circles]") {

  if (allLines.strokeColor.gray == "100" && allLines.fillColor.gray == "0" && allLines.fillColor != noColor) {

  alert("Correct");

  correct++;

  }

  else {

  alert("Incorrect");

  incorrect++;

  }

  }

  }

alert(correct + " correct circle and " + incorrect + " incorrect circles");

TOPICS
Scripting

Views

1.2K

Translate

Translate

Report

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

Guide , Oct 30, 2014 Oct 30, 2014

Ok, I'm awake now...

this seems to be working.

Hope this does what you want...

var doc = app.activeDocument; 

doc.selection = null; 

var correct = 0; 

var fixedS = 0; 

var fixedF = 0; 

var lines = 0; 

var layer = doc.layers.getByName('Layer Circles');  

var item = layer.pathItems;   

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

        if (item.closed){ 

            checkItem(item); 

        }else{ 

            item.selected = true; 

            lines++; 

        } 

var fix

...

Votes

Translate

Translate
Adobe
Guide ,
Oct 29, 2014 Oct 29, 2014

Copy link to clipboard

Copied

your question is not clear.

and your script has many errors and does not work.

Try this:

var doc = app.activeDocument;  

var correct = 0;   

var layer = doc.layers.getByName('Layer Circles');

var allLines = layer.pathItems;

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

  if (allLines.strokeColor.black == 100 && allLines.filled == true){  

  correct++; 

  }}

var incorrect = allLines.length - correct;

alert(correct + " correct circle and " + incorrect + " incorrect circles"); 

my test file has:

2 circles with no fill and a black stroke

2 circles with red fill and a black stroke

1 line with no fill and a black stroke

Layer 1 has the line, Layer Circles has the 4 circles.

result is 2 correct and 2 incorrect

its the red circles that are correct.

Votes

Translate

Translate

Report

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 30, 2014 Oct 30, 2014

Copy link to clipboard

Copied

What I want the script to check....

All items are on the layer Circles. Only items with K 0% fill AND K 100% stroke should exist on the Circles layer. So...

If the fill color and stroke color are correct the should be marked so (white filled circles with black stroke)

If the fill color is wrong it should be marked incorrect. (red filled circles with black stroke)

If the stroke color is wrong it should be marked incorrect.

If the stroke color is right but the item doesn't have a fill color (the line) it should be marked incorrect

Does that make sense? This is an error checking script. If I accidentally put the line on the circle layer I need to know. If I forget to format the circles to K 0% fill AND K 100% stroke I need to know.

Votes

Translate

Translate

Report

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
Guide ,
Oct 30, 2014 Oct 30, 2014

Copy link to clipboard

Copied

Will it only ever be circles an lines?

if so do you want the lines taken off the layer and the circles fixed to the correct fill?

Votes

Translate

Translate

Report

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 30, 2014 Oct 30, 2014

Copy link to clipboard

Copied

I will only be lines and circle that is correct. I don't want anything moved. I just planned on changing the stroke weight for the incorrect items to 10pt just so I can clearly see what is incorrect.

Votes

Translate

Translate

Report

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
Guide ,
Oct 30, 2014 Oct 30, 2014

Copy link to clipboard

Copied

ok, just wrote this.

its late and my bed time so have not tested it at all.

but you can give it a go.

Will set all closed paths on layer to White fill and black stroke, and finish with all open paths selected... I hope...

EDIT...

I have deleted this script as it has a few errors.

It was too late when I wrote it.

I will re post soon...

Votes

Translate

Translate

Report

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
Guide ,
Oct 30, 2014 Oct 30, 2014

Copy link to clipboard

Copied

Ok, I'm awake now...

this seems to be working.

Hope this does what you want...

var doc = app.activeDocument; 

doc.selection = null; 

var correct = 0; 

var fixedS = 0; 

var fixedF = 0; 

var lines = 0; 

var layer = doc.layers.getByName('Layer Circles');  

var item = layer.pathItems;   

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

        if (item.closed){ 

            checkItem(item); 

        }else{ 

            item.selected = true; 

            lines++; 

        } 

var fixedTot = item.length - correct - lines; 

alert("Of a total of " + item.length + " Items, \n" + correct + " Correct Items. \n\n" + fixedTot + " Items were fixed, \n" + fixedS + " needed Stroke fixed, \n" + fixedF + " needed Fill fixed. \n\n" + lines + " Open pathes have been selected \nand need to be removed from this layer."); 

 

function checkItem(item){    

  var ok = 0;

    if(item.strokeColor.cyan != 0 || item.strokeColor.magenta != 0 || item.strokeColor.yellow != 0 || item.strokeColor.black != 100){

     item.stroked = true;

        item.strokeColor.cyan = 0;

  item.strokeColor.magenta = 0;

  item.strokeColor.yellow = 0;

  item.strokeColor.black = 100;

  fixedS++;

  ok++; 

    } 

    if(item.fillColor.cyan != 0 || item.fillColor.magenta != 0 || item.fillColor.yellow != 0 || item.fillColor.black != 0){

        item.filled = true;

        item.fillColor.cyan = 0;

  item.fillColor.magenta = 0;

  item.fillColor.yellow = 0;

  item.fillColor.black = 0;

  fixedF++;

  ok++; 

    }

    if(ok==0){correct++;} 

}

Votes

Translate

Translate

Report

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 31, 2014 Oct 31, 2014

Copy link to clipboard

Copied

LATEST

Works GREAT! Thanks again!

Votes

Translate

Translate

Report

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