Skip to main content
Known Participant
August 11, 2015
Question

Scripting Gradient Stops

  • August 11, 2015
  • 2 replies
  • 490 views

Hey there,

I'm trying to hash out a script to adjust tint and opacity values, and so far have it really close to completion.  The only problem I've run into at this stage is the script breaking when a Gradient Color Stop has a fill of white(process, RGB in all my circumstances).  Here is the script I have so far for gradients:

var docRef = app.activeDocument; 

var paths = docRef.pathItems;

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

  if (paths.fillColor.typename == 'GradientColor' ) {

    var theStops = paths.fillColor.gradient.gradientStops;

  

    for (j=0; j< theStops.length; j++) {

            var valGradOp = theStops.opacity

            var valGradTint = theStops.color.tint

           

              if (theStops.color.tint == valGradTint && theStops.opacity == valGradOp){ 

                   theStops.color.tint = valGradOp; 

                   theStops.opacity = valGradTint;

                   }           

            

      //Everything Above works just fine until one of the stops is white.

      //To try and remedy this, I've used the same script from the solid color(non gradient)

      //section of the script which works just fine

            

            else if (theStops.color.typename == "RGBColor") { 

            if (Math.round(theStops.fillColor.red) == 255 && 

            Math.round(theStops.fillColor.green) == 255 && 

            Math.round(theStops.fillColor.blue) == 255 &&

            Math.round(theStops.opacity) == 100.0) {

               

                 

            theStops.opacity = 0;

        }

      }        

    }

  }

}     

The is about the end of my scripting knowledge, but the only solution I've thought of if it would be possible to script into this:

1. separate script to globally adjust all white to named Spot color, then adjust the opacity of that single to "0" globally as well.

Any help on this would be much appreciated.

Thank you!

This topic has been closed for replies.

2 replies

Qwertyfly___
Legend
August 12, 2015

if its that you want to reduce the amount of code you could put the block of code used in the gradient section and the solid section into a function.

ps. line 9 and 10 are missing semicolons

Silly-V
Legend
August 11, 2015

Hi, if you say that your script works ok like it does, with the extra block to deal with white stops, what's wrong with it?