11 Replies Latest reply on Jan 25, 2011 1:18 AM by [Jongware]-9BC6tI

    Document Spot color

    Chang_indd

      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

        • 1. Re: Document Spot color
          Gonterman1201 Level 1

          var myDocument=app.activeDocument;

           

          var mySwatch=myDocument.colors;

           

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


              if (mySwatch[i].model == ColorModel.SPOT){

           

              alert("there is a spot");
              }
          }
          1 person found this helpful
          • 2. Re: Document Spot color
            milligramme Level 3

            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[i].model == ColorModel.SPOT){

                   flag += 1;

                }
            }

            if ( flag > 1 ){
                alert("there is a spot");
            }
            1 person found this helpful
            • 3. Re: Document Spot color
              Chang_indd Level 1

              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

              • 4. Re: Document Spot color
                milligramme Level 3

                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[i].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);

                     };
                }
                • 5. Re: Document Spot color
                  [Jongware]-9BC6tI Level 4

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

                  • 6. Re: Document Spot color
                    Chang_indd Level 1

                    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

                    • 7. Re: Document Spot color
                      Chang_indd Level 1

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

                      • 8. Re: Document Spot color
                        milligramme Level 3

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

                         

                        the function has never executed...

                         

                        mg

                        • 9. Re: Document Spot color
                          Chang_indd Level 1

                          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

                          • 10. Re: Document Spot color
                            pkrk Level 1

                            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.

                            • 11. Re: Document Spot color
                              [Jongware]-9BC6tI Level 4

                              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.