Skip to main content
BEGINNER_X
Legend
May 21, 2015
Question

check Black color Text is 100% or not

  • May 21, 2015
  • 2 replies
  • 901 views

Hi All,

My request is,

1. find all the black color text

2. Content should be in 100% black

3. If not, select that content and alert("Selected content is not 100% black")

Please help for my request.

Thanks in advance

Siraj

This topic has been closed for replies.

2 replies

Disposition_Dev
Legend
May 21, 2015

ok, here we go. i got something that works. I'm sure many around here will chuckle silently to themselves when they see the methodology.. but this was the only way i could get it to work. It still works relatively quickly, though i still don't know how many text frames you're working with, so this may take a few seconds to run if there are a lot.

Let me know how this works for ya. =)

function checkBlackText(){

  var docRef = app.activeDocument;

  var layers = docRef.layers;

  var tF = docRef.textFrames;

  var checkLayer;

  var wrongColor = [];

  function existCheckLayer(){

  try {

  checkLayer = layers.getByName("Check Layer");

  checkLayer.remove(); //make sure there's no extraneous artwork on the layer

  checkLayer = layers.add();

  checkLayer.name = "Check Layer";

  }

  catch(err){

  checkLayer = layers.add();

  checkLayer.name = "Check Layer";

  }

  }

  docRef.selection = null;

  for (i=0; i<tF.length; i++){

  existCheckLayer();

  var CTF = tF;

  CTF.duplicate(checkLayer, ElementPlacement.PLACEATEND);

  var checkFrame = checkLayer.textFrames[0];

  checkFrame.createOutline();

  if (checkLayer.compoundPathItems.length > 0){

  var path = checkLayer.groupItems[0].compoundPathItems[0].pathItems[0];

  alert(path.fillColor);

  if (path.fillColor.black != 100 || path.fillColor.cyan > 0 || path.fillColor.magenta > 0 || path.fillColor.yellow > 0){

  wrongColor.push(CTF);

  }

  }

  else if (checkLayer.groupItems.length > 0){

  var group = checkLayer.groupItems[0];

  var path = group.compoundPathItems[0].pathItems[0];

  if (path.fillColor.black != 100 || path.fillColor.cyan > 0 || path.fillColor.magenta > 0 || path.fillColor.yellow > 0){

  wrongColor.push(CTF);

  }

  }

  }

  if(wrongColor.length > 0){

  docRef.selection = null;

  for (s=0; s< wrongColor.length; s++){

  wrongColor.selected = true;

  }

  alert("Selected Items Are Not 100% K");

  }

  var deleteCheckLayer = layers.getByName("Check Layer").remove();

}

checkBlackText();

Qwertyfly___
Legend
May 21, 2015

‌jjust as a thought.

loop pageitems to select textframes.

activate the recolor artwork dialog

then just manually set near blacks to black.

BEGINNER_X
Legend
May 22, 2015

Hi William/Qwerty,

Thank you spending your valuable time for me.

I tried your code, in simple document.

Script run without error. But the output not comes(no alert for [selected items are not 100%])

Look at the screenshot of simple sample document.

CODING:

As per my thinking, Line number 45 need to be fix.

Because alert 3 not comes in my end.

Could you please help.

#target Illustrator

function checkBlackText(){ 

  var docRef = app.activeDocument; 

  var layers = docRef.layers; 

  var tF = docRef.textFrames; 

  var checkLayer; 

  var wrongColor = []; 

 

  function existCheckLayer(){ 

 

  try { 

  checkLayer = layers.getByName("Check Layer"); 

  checkLayer.remove(); //make sure there's no extraneous artwork on the layer 

  checkLayer = layers.add(); 

  checkLayer.name = "Check Layer"; 

  } 

  catch(err){ 

  checkLayer = layers.add(); 

  checkLayer.name = "Check Layer"; 

  } 

  } 

  docRef.selection = null; 

 

 

  for (i=0; i<tF.length; i++){ 

  existCheckLayer(); 

  var CTF = tF

  CTF.duplicate(checkLayer, ElementPlacement.PLACEATEND); 

  var checkFrame = checkLayer.textFrames[0]; 

  checkFrame.createOutline(); 

  if (checkLayer.compoundPathItems.length > 0){ 

  var path = checkLayer.groupItems[0].compoundPathItems[0].pathItems[0]; 

  alert(path.fillColor); 

  if (path.fillColor.black != 100 || path.fillColor.cyan > 0 || path.fillColor.magenta > 0 || path.fillColor.yellow > 0){ 

  wrongColor.push(CTF); 

  }} 

  else if (checkLayer.groupItems.length > 0){ 

      alert("yyyess")

  var group = checkLayer.groupItems[0]; 

  alert("1")

  var path = group.compoundPathItems[0].pathItems[0]; 

  alert("2")

  if (path.fillColor.black != 100 || path.fillColor.cyan > 0 || path.fillColor.magenta > 0 || path.fillColor.yellow > 0){    //i hope, this line having issues

      alert("3")

  wrongColor.push(CTF); 

  }}} 

  if(wrongColor.length > 0){ 

  docRef.selection = null; 

  for (s=0; s< wrongColor.length; s++){ 

  wrongColor.selected = true; 

  } 

  alert("Selected Items Are Not 100% K"); 

  } 

 

  var deleteCheckLayer = layers.getByName("Check Layer").remove(); 

checkBlackText();

Disposition_Dev
Legend
May 21, 2015

Are you looking for 100% tint of "Black" spot color or "0,0,0,100"?

is there text of a different color as well that you'd like to ignore? how complicated are the files you'd like to work with? a request like this probably requires looping through every item of the document which can take quite a while if there are a lot of objects.

BEGINNER_X
Legend
May 21, 2015

Hi William,

FYI., New to Illustrator and Illustrator scripting.

Thanks for the very Quick response...

1. All text should be in "0,0,0,100". (if not need to alert)

2. No need to check PageItems

3. May the Different color is also comes.

Just Trying Script, but fails

#target Illustrator

var myBlack = new CMYKColor();

myBlack.cyan = 0;

myBlack.magenta = 0;

myBlack.yellow = 0;

myBlack.black = 100;

 

var myTF = app.activeDocument.textFrames;

for(i=0; i<myTF.length; i++)

{

    var myChar = myTF.characters;

    for(j=0; j<myChar.length; j++)

    {

         if(myChar.characterAttributes.fillColor.name != myBlack)

         {

             alert("got it")

             }

        }

    }

Thanks

Siraj

Disposition_Dev
Legend
May 21, 2015

Cool. You're farther along than i thought. You're on the right track.. However it seems that characterAttributes.fillColor is not a property of textFrames.characters.

I've played around with all the combinations i can come up with, but none of them seem to work. the scripting guide shows that 'characters' is a property of textFrames, but the only available properties of 'characters' are: length, parent and typename.

looks like 'characterAttributes' is only a property of 'characterStyles' which is not a property of 'characters' or 'textFrames'. all of this seems very dumb, but i'm sure someone with more experience may be able to shed some light.

due to the above observations, i'd posit that a possible solution (albeit not the very fastest one) would be to create a throwaway layer, loop through the textFrames, duplicate each textFrame to the throwaway layer, create outlines, check the fillColor of the resulting pathItem, then remove(); and go to the next textFrame.

let me see what i can put together.