16 Replies Latest reply on Sep 25, 2015 5:09 AM by Stephen_A_Marsh

    Change Spot Colour Opacity Value to Tint Value

    Stephen_A_Marsh Adobe Community Professional

      Does anyone know of a script to change all spot colour objects that have an opacity value to the corresponding tint value of the spot colour? It could also be for process colours, global or not – however the main thing is spots.


      If an object uses a spot colour that has an opacity of say 13%, then it should be set to opacity 100% and the spot colour tint value of 13%. If an object was 75% opacity, then it should be set to 75% tint at 100% opacity etc. All the way through the tonal range for all objects.


      It would be nice if the blend mode of the spot colour was set to normal if it was something else (darken, multiply etc). I guess it would also be great if there was an option to set the object to overprint if the blend mode used was darken or multiply, but that is the icing on the cake. The main thing is mapping the spot object opacity value to the spot tint value and setting opacity back to 100%.


      I would have thought that this would be a common enough issue in packaging prepress, however I have had no success in finding such a script.

        • 1. Re: Change Spot Colour Opacity Value to Tint Value
          Qwertyfly... Level 4

          this is not a hard one to do.

          but would a flatten transparency be a better option?

           

          here is what you want in its most basic form.

          var doc = app.activeDocument;
          var items = doc.pageItems;
          for(var i = 0; i<items.length;i++){
              items[i].fillColor.tint = items[i].opacity;
              items[i].opacity = 100;
          }
          

           

           

          image of before:

          t.JPG

           

          and image of after:

          tt.JPG

           

          you can quickly see the issue once you remove your transparency.

          • 2. Re: Change Spot Colour Opacity Value to Tint Value
            Stephen_A_Marsh Adobe Community Professional

            That is great Qwertyfly, thank you so much! Even six lines of code is beyond my abilities…

             

            Although this script produces the desired change in objects with opacity below 100%, the sript adversely affects spot colour objects that do not have opacity applied.

             

            I have tried only selecting the desired objects to change, inverse selection and locking or hiding the objects that don’t use opacity – however they are still affected by the script.

             

            Is there an easy way to limit this script change to only objects that are less than 100% opacity?

             

            Flattening transparency preserving spots sort of works, however it faithfully preserves overlapping regions and attempts to visually represent the interaction of opacity in the flattened document. Opacity applied to spot and tint applied to spot are similar, but subtly different – so I prefer your script results.

            • 3. Re: Change Spot Colour Opacity Value to Tint Value
              Qwertyfly... Level 4

              we can just add an If statement.

               

              If opacity not 100

              set tint to opacity

              set opacity to 100

              else do nothing

               

              I also added a Line that has been commented out.

              if you remove the // from the start of line 3 and add // to the start of line 2.

              then it will only act on selected items.

               

              var doc = app.activeDocument;
              var items = doc.pageItems; // this line states that items is an array of all page Items
              //var items = doc.selection; // this line states that items is an array of all selected items
              for(var i = 0; i<items.length;i++){
                  if(items[i].opacity != 100){
                      items[i].fillColor.tint = items[i].opacity;
                      items[i].opacity = 100;
                  }
              }
              

               

              remember this is about as basic as it gets and may do undesired things in certain situations.

              ie.

              if tint = 50 & opacity = 50.

              tint gets set to opacity and opacity is set to 100

              tint now 50 and opacity is now 100.

              this should be 25.

               

              so to fix that we need some maths (this example I have switched to selection mode)

              var doc = app.activeDocument;
              //var items = doc.pageItems; // this line states that items is an array of all page Items
              var items = doc.selection; // this line states that items is an array of all selected items
              for(var i = 0; i<items.length;i++){
                  if(items[i].opacity != 100){
                      items[i].fillColor.tint = items[i].fillColor.tint*(items[i].opacity/100);
                      items[i].opacity = 100;
                  }
              }
              

               

              but remember tint and opacity are not equal.

              you will probably be modifying a lot of your colours.

              ie.

              t2.JPG

              • 4. Re: Change Spot Colour Opacity Value to Tint Value
                Stephen_A_Marsh Adobe Community Professional

                Thank you Qwertyfly, I really do appreciate your time and knowledge!


                I managed to create a second version that targets strokes.


                I can’t combine a selection of fills apply script, select strokes apply script in a script… so I have had to tie the two scripts together in an action that references a selection script. Talk about a hack! Problem is with CS6 that inserted scripts are lost from the action when Illustrator is restarted.


                Thanks again!

                • 5. Re: Change Spot Colour Opacity Value to Tint Value
                  Qwertyfly... Level 4

                  you lose your original opacity value if its run as separate scripts.

                   

                  here is how to do it as one script

                   

                  var doc = app.activeDocument;  
                  //var items = doc.pageItems; // this line states that items is an array of all page Items  
                  var items = doc.selection; // this line states that items is an array of all selected items  
                  for(var i = 0; i<items.length;i++){  
                      if(items[i].opacity != 100){  
                          if(items[i].filled === true){
                              items[i].fillColor.tint = items[i].fillColor.tint*(items[i].opacity/100);
                          }
                          if(items[i].stroked === true){
                              items[i].strokeColor.tint = items[i].strokeColor.tint*(items[i].opacity/100);
                          }
                          items[i].opacity = 100;  
                      }  
                  } 
                  

                   

                   

                  As for actions losing the script on restart.

                  CC+ still has the same issue.

                  very painfull

                  • 6. Re: Change Spot Colour Opacity Value to Tint Value
                    Qwertyfly... Level 4

                    here is a more complete script.

                    bundled in a function to keep global space clean.

                    and should deal with Spot, CMYK, and RGB colours.

                     

                    let me know if you find it does unexpected things...

                     

                    function RemoveOpacity(){
                        // to work on selected items only set to SEL
                        // to work on whole document set to ALL
                        var work_on = "SEL";
                        //---------------------------------------------------------
                        var doc = app.activeDocument;  
                        if(work_on === 'SEL'){
                            var items = doc.selection;
                        }else if(work_on === 'ALL'){
                            var items = doc.pathItems;
                        }else{
                            alert('the "work_on" variable is not set correctly');
                            return;
                        }
                        for(var i = 0; i<items.length;i++){  
                            if(items[i].opacity != 100){  
                                if(items[i].filled === true && items[i].fillColor == '[SpotColor]'){
                                    items[i].fillColor.tint = items[i].fillColor.tint*(items[i].opacity/100);
                                }else if(items[i].filled === true && items[i].fillColor == '[CMYKColor]'){
                                    items[i].fillColor.cyan = items[i].fillColor.cyan*(items[i].opacity/100);
                                    items[i].fillColor.magenta = items[i].fillColor.magenta*(items[i].opacity/100);
                                    items[i].fillColor.yellow = items[i].fillColor.yellow*(items[i].opacity/100);
                                    items[i].fillColor.black = items[i].fillColor.black*(items[i].opacity/100);
                                }else if(items[i].filled === true && items[i].fillColor == '[RGBColor]'){
                                    items[i].fillColor.red = items[i].fillColor.red+(255-items[i].fillColor.red)*(items[i].opacity/100);
                                    items[i].fillColor.blue = items[i].fillColor.blue+(255-items[i].fillColor.blue)*(items[i].opacity/100);
                                    items[i].fillColor.green = items[i].fillColor.green+(255-items[i].fillColor.green)*(items[i].opacity/100);
                                }
                                if(items[i].stroked === true && items[i].strokeColor == '[SpotColor]'){
                                    items[i].strokeColor.tint = items[i].strokeColor.tint*(items[i].opacity/100);
                                }else if(items[i].stroked === true && items[i].strokeColor == '[CMYKColor]'){
                                    items[i].strokeColor.cyan = items[i].strokeColor.cyan*(items[i].opacity/100);
                                    items[i].strokeColor.magenta = items[i].strokeColor.magenta*(items[i].opacity/100);
                                    items[i].strokeColor.yellow = items[i].strokeColor.yellow*(items[i].opacity/100);
                                    items[i].strokeColor.black = items[i].strokeColor.black*(items[i].opacity/100);
                                }else if(items[i].stroked === true && items[i].strokeColor == '[RGBColor]'){
                                    items[i].strokeColor.red = items[i].strokeColor.red+(255-items[i].strokeColor.red)*(items[i].opacity/100);
                                    items[i].strokeColor.blue = items[i].strokeColor.blue+(255-items[i].strokeColor.blue)*(items[i].opacity/100);
                                    items[i].strokeColor.green = items[i].strokeColor.green+(255-items[i].strokeColor.green)*(items[i].opacity/100);
                                }
                                items[i].opacity = 100;  
                            }  
                        }
                    }
                    RemoveOpacity();
                    
                    • 7. Re: Change Spot Colour Opacity Value to Tint Value
                      Stephen_A_Marsh Adobe Community Professional

                      Qwertyfly, I have not performed exhaustive tests, however this latest script appears to be a thing of beauty! Thank you so much. I’ll let you know how things go and I’ll mark your latest post as the correct answer once I have tested the script more. Thank you!

                      • 8. Re: Change Spot Colour Opacity Value to Tint Value
                        Qwertyfly... Level 4

                        no problem

                        im glad I could help

                        • 9. Re: Change Spot Colour Opacity Value to Tint Value
                          Stephen_A_Marsh Adobe Community Professional

                          Thanks Qwertyfly, I have tested this and I am happy, the only place where I see a problem is with gradients, however I imagine that it is hard to deal with this as it would involve having to figure out and adjust the specific gradient slider stop opacity.

                           

                          Thank you again for your experience, time and willingness to freely help the script challenged out there!

                          • 10. Re: Change Spot Colour Opacity Value to Tint Value
                            Qwertyfly... Level 4

                            I'll think on it and get back to you.

                            should not be too hard to deal with gradients

                            • 11. Re: Change Spot Colour Opacity Value to Tint Value
                              Stephen_A_Marsh Adobe Community Professional

                              Thanks Qwertyfly, of course another thing to watch out for is opacity applied through the appearance panel, as it is not a “true” object until it is expanded, it too is not picked up by the script. Again, not a big deal however I thought it worth mentioning while we are discussing items that are not handled by the script.

                              • 12. Re: Change Spot Colour Opacity Value to Tint Value
                                Qwertyfly... Level 4

                                I've got a new version put together to deal with gradients.

                                but it's giving me some issues.

                                I'm sure its a dumb error so will post a new topic to get another brain to look over it for me.

                                will let you know once it's working...

                                 

                                as for opacity applied from appearance panel. hmmm I'll check it out...

                                • 13. Re: Change Spot Colour Opacity Value to Tint Value
                                  Stephen_A_Marsh Adobe Community Professional

                                  Thanks Qwertyfly, please don’t expend too much energy on my behalf, I am grateful for the work that you have put in so far! Thanks again.

                                  • 14. Re: Change Spot Colour Opacity Value to Tint Value
                                    Qwertyfly... Level 4

                                    I do it because I enjoy it.

                                    And now I need to know why it's not doing what I expect it to.

                                    I'm looking forward to finding out where I went wrong.

                                    and if it's a bug with illustrator then I'm looking forward to finding some hack way around it...

                                    • 15. Re: Change Spot Colour Opacity Value to Tint Value
                                      Qwertyfly... Level 4

                                      ok, I think i've worked a way around the bug I was having.

                                      try this one out.

                                       

                                      now works for greycolours or graycolors.

                                      and should be working for gradients.

                                       

                                      let me know how it goes.

                                       

                                      I'll have a look at the link you sent me and see if we can tweak that.

                                      as for opacity added to the appearance panel, I don't think JS has access to it.

                                      only option would be to expand

                                      but I can't even find a way to test if it has more then 1 stroke or fill

                                       

                                       

                                      there are many other cases this script will not work with including opacity masks.

                                       

                                      function RemoveOpacity(){  
                                          // to work on selected items only set to SEL  
                                          // to work on whole document set to ALL  
                                          var work_on = "SEL";  
                                          //---------------------------------------------------------  
                                          function changeColor(obj,op){
                                              if(obj == '[SpotColor]'){  
                                                  obj.tint = obj.tint*op;  
                                              }else if(obj == '[CMYKColor]'){  
                                                  obj.cyan = obj.cyan*op;  
                                                  obj.magenta = obj.magenta*op;  
                                                  obj.yellow = obj.yellow*op;  
                                                  obj.black = obj.black*op;  
                                              }else if(obj == '[RGBColor]'){  
                                                  obj.red = obj.red+(255-obj.red)*op;  
                                                  obj.blue = obj.blue+(255-obj.blue)*op;  
                                                  obj.green = obj.green+(255-obj.green)*op;  
                                              }else if(obj == '[GrayColor]'){
                                                  obj.gray = obj.gray*op;
                                              }
                                              return obj;
                                          }
                                          var doc = app.activeDocument;    
                                          if(work_on === 'SEL'){  
                                              var items = doc.selection;  
                                          }else if(work_on === 'ALL'){  
                                              var items = doc.pathItems;  
                                          }else{  
                                              alert('the "work_on" variable is not set correctly');  
                                              return;  
                                          }  
                                          for(var i = 0; i<items.length;i++){ 
                                              if(items[i].filled === true){
                                                  if(items[i].fillColor == '[GradientColor]'){
                                                      for(var j = 0; j<items[i].fillColor.gradient.gradientStops.length;j++){
                                                          items[i].fillColor.gradient.gradientStops[j].color = changeColor(items[i].fillColor.gradient.gradientStops[j].color,(items[i].fillColor.gradient.gradientStops[j].opacity/100)*(items[i].opacity/100));
                                                          items[i].fillColor.gradient.gradientStops[j].opacity = 100;
                                                      }
                                                  }else{
                                                      changeColor(items[i].fillColor,items[i].opacity/100); 
                                                  }
                                              }
                                              if(items[i].stroked === true){
                                                  if(items[i].strokeColor == '[GradientColor]'){
                                                      for(var j = 0; j<items[i].strokeColor.gradient.gradientStops.length;j++){
                                                          items[i].strokeColor.gradient.gradientStops[j].color = changeColor(items[i].strokeColor.gradient.gradientStops[j].color,(items[i].strokeColor.gradient.gradientStops[j].opacity/100)*(items[i].opacity/100));
                                                          items[i].strokeColor.gradient.gradientStops[j].opacity = 100;
                                                      }
                                                  }else{
                                                      changeColor(items[i].strokeColor,items[i].opacity/100); 
                                                  }
                                              }
                                              items[i].opacity = 100;    
                                          }  
                                      }  
                                      RemoveOpacity(); 
                                      
                                      • 16. Re: Change Spot Colour Opacity Value to Tint Value
                                        Stephen_A_Marsh Adobe Community Professional

                                        This new one correctly handled the simple gradient test, which only used a start and end stop. Well done!