0 Replies Latest reply on Oct 11, 2012 11:14 AM by aguisler86

    Adding a tint swatch of a color if the tint is being used? [JS][CS5]

    aguisler86

      Hey there, I'm totally new to this scripting stuff and I've already pieced together a few scripts and much to my surprise it seems to be working!

       

      There is one thing I cannot find out how to do, though.  I think it would be possible.  Anyways, I'm looking for a script that will add a tint swatch of a color if the tint is being used.  So, say I have color1 in my swatches that is being used in the document and also in the document a 25% tint of color1 is being used.  I need the 25% tint to be made into a swatch as well.

       

      Is there a simple way to have a script "read" the document for unused tints and add them as a swatch?

       

      This is what I have pieced together for my script so far.  It is basically all from these two threads.

      http://forums.adobe.com/message/1106498

      http://forums.adobe.com/message/4115524

       

      //  Delete unused Character and Paragraph Styles
      var myDoc = app.activeDocument;
      var myParStyles = myDoc.paragraphStyles;
      var myCharStyles = myDoc.characterStyles;
      
      for (j = myParStyles.length-1; j >= 2; j-- ) {
         removeUnusedParaStyle(myParStyles[j]);
      }
      
      for (i = myCharStyles.length-1; i >= 1; i-- ) {
         removeUnusedCharStyle(myCharStyles[i]);
      }
      
      function removeUnusedParaStyle(myPaStyle) {
         app.findTextPreferences = NothingEnum.nothing;
         app.changeTextPreferences = NothingEnum.nothing;
         app.findTextPreferences.appliedParagraphStyle = myPaStyle;
         var myFoundStyles = myDoc.findText();
            if (myFoundStyles == 0) {
               myPaStyle.remove();
            }
         app.findTextPreferences = NothingEnum.nothing;
         app.changeTextPreferences = NothingEnum.nothing;
      }
      
      function removeUnusedCharStyle(myChStyle) {
         app.findTextPreferences = NothingEnum.nothing;
         app.changeTextPreferences = NothingEnum.nothing;
         app.findTextPreferences.appliedCharacterStyle = myChStyle;
         var myFoundStyles = myDoc.findText();
            if (myFoundStyles == 0) {
               myChStyle.remove();
            }
         app.findTextPreferences = NothingEnum.nothing;
         app.changeTextPreferences = NothingEnum.nothing;
      }
      // Delete unused Tags
      app.activeDocument.deleteUnusedTags();
      
      
      // Delete unused Swatches and Add Unnamed Colors
      app.menuActions.item("$ID/Add All Unnamed Colors").invoke();
      var myIndesignDoc = app.activeDocument;
      var myUnusedSwatches = myIndesignDoc.unusedSwatches;
      
      
      for (var s = myUnusedSwatches.length-1; s >= 0; s--) {
           var mySwatch = myIndesignDoc.unusedSwatches[s];
           var name = mySwatch.name;
       // alert (name);
        if (name != ""){
       mySwatch.remove();
       }
      }
      
      

       

       

      Thanks in advance for any responses.  I hope I can get this working so I have one less step to do while revising old documents!