11 Replies Latest reply on Jan 12, 2015 10:07 AM by MrJHMaximus

    Giving Opacity the same value as fill color (Inverting Opacity/Fill)

    MrJHMaximus

      I am looking to add a script that would take the fill value of swatches in my art file, and apply those values to the opacity of each swatch.  I would also like to be able to adjust the fill value to be 100% when finished.  I have a javascript that I thought would work, but it has no effect on any of the objects in the file.

       

      Example:

      Original Art: Object 1: Fill 50%, Opacity 100% // Object 2: Fill 60%, Opacity 100%

      Desired Result: Object 1: Fill 100%, Opacity 50% // Object 2: Fill 100%, Opacity 60%

       

      Any help would be much appreciated.

        • 1. Re: Giving Opacity the same value as fill color (Inverting Opacity/Fill)
          williamadowling Level 4

          sorry that question was dumb and unnecessary so i deleted it..

           

          here is the absolutely most basic and simple way to do this. it's not the ideal way because it relies on the hard number values. but with this you should be able to devise some other variables or arrays to make it work with values that don't have to be hard coded.

           

          var docRef = app.activeDocument;
          var paths = docRef.pathItems;
          
          
          for (i=0; i< paths.length; i++){
              if (paths[i].fillColor.tint == 50 && paths[i].opacity == 100){
                  paths[i].fillColor.tint = 100;
                  paths[i].opacity = 50;
                  
                  }
              else if (paths[i].fillColor.tint == 100 && paths[i].opacity == 50){
                  paths[i].fillColor.tint = 50;
                  paths[i].opacity = 100;
                 
                  }
              }
          
          • 2. Re: Giving Opacity the same value as fill color (Inverting Opacity/Fill)
            MrJHMaximus Level 1

            Any way to make this work on gradients as well?

            • 3. Re: Giving Opacity the same value as fill color (Inverting Opacity/Fill)
              MrJHMaximus Level 1

              This code is right on track, thank you so much!  I'm still playing with it to get it set up to include and exclude things based on the current need, but this should do nicely.  I notice that this doesn't work on gradients at all, if there a way to include the individual fills of each gradient into the paths as they are called, or would I have to call each stop in the gradient?

              • 4. Re: Giving Opacity the same value as fill color (Inverting Opacity/Fill)
                williamadowling Level 4

                i'm still really new to all of this as well.. the way i understand it.. you'd need to call each stop.. unless of course you could create a graphic style and then reference the object by said graphic style? however, i know this is sort of antithetical to the idea of scripting these changes.. especially if you have a wide variation of transparencies, tints and gradients that you need to script.

                 

                without knowing the scope of the changes you need to make and the number of files etc.. it's hard to say what the best approach is.

                • 5. Re: Giving Opacity the same value as fill color (Inverting Opacity/Fill)
                  MrJHMaximus Level 1

                  That seems to be what I'm seeing in Adobe's publications as well.  I'm going to keep digging and see if there's a way to call each gradient as a path and then maybe apply the same script from earlier within that path.  The problem seems to stem from the fact that gradients as a fill appear with no static value.  Thank you for your assistance, if you do have a brainwave about how to do that, I'd appreciate it.  I will post anything as I find it.

                   

                  //As far as approach, looking to do this for as many gradients as appear in each file, and only doing one file at a time.  Gradients may have anywhere from two to 6 stops.

                  • 6. Re: Giving Opacity the same value as fill color (Inverting Opacity/Fill)
                    williamadowling Level 4

                    yea.. the code will likely get pretty complex if you don't know how many gradient stops there will be. ultimately, it's going to require identifying that pathItem[index] has a gradient, then determining how many stops, then pushing the information from each stop into an array, then applying that information from the array into the object you want to replace (but before applying the information, you need to extract the info from those stops and push to a separate array)..

                     

                    i might be of more help if i can see the file you're working with.. how many gradients are we talking here? and will each gradient have just 1 mirror object? or is there one object with gradient stops [a, b, c, d, e] and then several objects with gradient stops [aa, bb, cc, dd, ee]?

                    • 7. Re: Re: Giving Opacity the same value as fill color (Inverting Opacity/Fill)
                      MrJHMaximus Level 1

                      Here is one of the test files I'm using.  Let me know if you have problems accessing, the sharing settings should be updated though.  This is probably the most complex gradients that the script would ever be used for, seeing as anything more complex would be best proofed manually.

                       

                      To answer your question, typically a range of 2 - 4 paths of gradients with varying gradient stops for each.

                      • 8. Re: Re: Giving Opacity the same value as fill color (Inverting Opacity/Fill)
                        williamadowling Level 4

                        ok. so you need to make the white stops pink and the pink stops white? i'm not seeing how tints/opacity (as per your original question) fits into that picture.

                        • 9. Re: Re: Giving Opacity the same value as fill color (Inverting Opacity/Fill)
                          MrJHMaximus Level 1

                          I need to make white stops (Fill of 0) have an opacity of 0 (for overlay) and in this file, stops of magenta have an opacity equal to their Fill.  Some of the fill values in the gradients for magenta is set to a value of 60 right now (at the top of each of the coils).  Any path with a fill value of 100 would only keep the opacity at 100 as well, so it wouldn't show through for overlay or if the file were set up with overprint. 

                          • 10. Re: Re: Giving Opacity the same value as fill color (Inverting Opacity/Fill)
                            williamadowling Level 4

                            ok.. so i did some cursory research and i think this is probably over my head.. at least for the time being. i'm at work so i can't spend too much time troubleshooting this.. sorry. i thought it might be more simple.

                             

                            but basically, like i said above.. your task is to loop through each pathItem and push the gradient stop values into arrays (var stop1 = [];, var stop2 = []; etc). then you could write an if clause to determine the value of each array in sequence and then you should be able to use something like the code i posted at the beginning of this thread.

                             

                            if (stop1 == some opacity value){

                                 apply tint instead of opacity (or vice versa) to the first gradient stop in your current path

                            }

                             

                            sorry i can't be of more help. and i'm sure someone will step in here and tell me that pushing to an array is a terrible idea.. i just don't know how the gradient stops are written.. i'm sure this could be done all within the same function.

                            • 11. Re: Re: Giving Opacity the same value as fill color (Inverting Opacity/Fill)
                              MrJHMaximus Level 1

                              Sounds good.  Thanks so much for your help on this, I will take a look at the code soon and see if I can play with it.  Much appreciated! (Going to mark this as unanswered again for the time being to get views on it, but will eventually push this to a new thread and mark as completed once I have a chance).