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

Document Spot color

New Here ,
Jan 19, 2011 Jan 19, 2011

Copy link to clipboard

Copied

Hi All,

I require a script to find if there is any spot color used in my indesin document.

Can anyone please provide me the code.

Regards,

Chang

TOPICS
Scripting

Views

1.5K

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

Contributor , Jan 21, 2011 Jan 21, 2011

oh Sorry, it's must be " If (flag > 0)  " or " If (flag >= 1) "

the function has never executed...

mg

Votes

Translate

Translate
Engaged ,
Jan 19, 2011 Jan 19, 2011

Copy link to clipboard

Copied

var myDocument=app.activeDocument;

var mySwatch=myDocument.colors;

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


    if (mySwatch.model == ColorModel.SPOT){

    alert("there is a spot");
    }
}

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
Contributor ,
Jan 19, 2011 Jan 19, 2011

Copy link to clipboard

Copied

Hi

i fixed it a little bit. even if many spot colors exist, it alert only once.

var myDocument=app.activeDocument;

var mySwatch=myDocument.colors;

var flag = 0;

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


    if (mySwatch.model == ColorModel.SPOT){

       flag += 1;

    }
}

if ( flag > 1 ){
    alert("there is a spot");
}

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
New Here ,
Jan 20, 2011 Jan 20, 2011

Copy link to clipboard

Copied

Thank you both of you.

This code is showing me spot color from swatches too whereas my document has no spot color.

Acutally, my requirement is to alert when my document has appplied spot color and ignore spot color from swatches if it is not applied in the document.

Thanks,

Chang

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
Contributor ,
Jan 21, 2011 Jan 21, 2011

Copy link to clipboard

Copied

Hi,

Checking applied color must be scan all objects!! of the document,

Here is a code, it scans texts and frame objects(Text Frame, Rectangle,,,,)

but not support table and cell.

mg

Thanks

var doc = app.activeDocument;
var mySwatch = doc.colors;
var flag = 0;

for (var i=0; i < mySwatch.length; i++){
    if (mySwatch.model == ColorModel.SPOT){
       flag += 1;
    }
}

if ( flag > 1 ){
    check_spot(doc);
}
else{
     alert("no spot color");
}

function check_spot (doc) {
     // scan text story exclude table and cell
     var flg2 = flg3 = flg4 = flg5 = 0
     var story_obj = doc.stories;
     for (var sti=0, stiL=story_obj.length; sti < stiL ; sti++) {
          var tsr_obj = story_obj[sti].textStyleRanges;
          for (var tsi=0, tsiL=tsr_obj.length; tsi < tsiL ; tsi++) {
               try{
                    if (tsr_obj[tsi].fillColor.model == ColorModel.SPOT) {
                         flg2 += 1;               
                    };
               }catch(e){$.writeln(e);}
               try{
                    if (tsr_obj[tsi].strokeColor.model == ColorModel.SPOT) {
                         flg3 += 1;               
                    };
               }catch(e){$.writeln(e);}
          };
     };

     // scan pageitem
     var all_p_item = doc.allPageItems;
     for (var api=0, apiL=all_p_item.length; api < apiL ; api++) {
          try{
               if (all_p_item[api].fillColor.model == ColorModel.SPOT) {
                    flg4 += 1;
               };
          }catch(e){$.writeln(e);}
          try{
               if (all_p_item[api].strokeColor.model == ColorModel.SPOT) {
                    flg5 += 1;               
               };

          }catch(e){$.writeln(e);}
     };

     // result message
     if ( flg2 > 0 || flg3 > 0 || flg4 > 0 || flg5 > 0 ) {
          var tx_fill_color   = flg2 > 0 ? "used spotcolor in text fill " + flg2 + "part" : "";
          var tx_stroke_color = flg3 > 0 ? "used spotcolor in text stroke " + flg3 + "part" : "";
          var pi_fill_color   = flg4 > 0 ? "used spotcolor in page item fill " + flg4 + "part" : "";
          var pi_stroke_color = flg5 > 0 ? "used spotcolor in page item stroke " + flg5 + "part" : "";
          var rslt = [tx_fill_color, tx_stroke_color, pi_fill_color, pi_stroke_color].join('\n')

          alert("result\n" + rslt);

     };
}

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
Advocate ,
Jan 21, 2011 Jan 21, 2011

Copy link to clipboard

Copied

Why not remove all unused colors and then go over the remaining list with the first script?

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
New Here ,
Jan 21, 2011 Jan 21, 2011

Copy link to clipboard

Copied

Hi! Milligramm,

Firstly, I would like to thank for your kindly support.

I run this script code with my pageitems fill, text stroke, but it gives error "no spot color".

Is there anything missing in this code.

Jongware, thanks for your suggest. Actually, this type of condition we face our production and I am not authorize to delete any styles from supplied files. Hope you understand.

Thanks,
Chang

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
New Here ,
Jan 21, 2011 Jan 21, 2011

Copy link to clipboard

Copied

I caught the error. On line no. 9 If (flag >1) should change to If (flag>0). Am I right?

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
Contributor ,
Jan 21, 2011 Jan 21, 2011

Copy link to clipboard

Copied

oh Sorry, it's must be " If (flag > 0)  " or " If (flag >= 1) "

the function has never executed...

mg

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
New Here ,
Jan 21, 2011 Jan 21, 2011

Copy link to clipboard

Copied

Thanks, you are so nice.

I also want to show my used spot color name as alert in this code.

What code require for show used spot color name.

Please suggest.

Thanks,

Chang

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
Explorer ,
Jan 24, 2011 Jan 24, 2011

Copy link to clipboard

Copied

Keep in mind that the InDesign document could also have files placed in them such as PDFs and EPS that could have Spots embedded in them as well.

You would be ignoring those at the point you seem to be at now.

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
Advocate ,
Jan 25, 2011 Jan 25, 2011

Copy link to clipboard

Copied

LATEST

Yeah, well, scripting is just not up to this.

I'd simply create a Preflight profile that forbids all Spot colors -- at least that'll list all occurrences, to check manually.

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