Skip to main content
Known Participant
January 8, 2015
Answered

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

  • January 8, 2015
  • 2 replies
  • 1310 views

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.

This topic has been closed for replies.
Correct answer Disposition_Dev

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.fillColor.tint == 50 && paths.opacity == 100){

        paths.fillColor.tint = 100;

        paths.opacity = 50;

       

        }

    else if (paths.fillColor.tint == 100 && paths.opacity == 50){

        paths.fillColor.tint = 50;

        paths.opacity = 100;

      

        }

    }

2 replies

Known Participant
January 12, 2015

Any way to make this work on gradients as well?

Disposition_Dev
Disposition_DevCorrect answer
Legend
January 9, 2015

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.fillColor.tint == 50 && paths.opacity == 100){

        paths.fillColor.tint = 100;

        paths.opacity = 50;

       

        }

    else if (paths.fillColor.tint == 100 && paths.opacity == 50){

        paths.fillColor.tint = 50;

        paths.opacity = 100;

      

        }

    }

Known Participant
January 12, 2015

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?

Disposition_Dev
Legend
January 12, 2015

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.