2 Replies Latest reply on Aug 11, 2015 5:24 PM by Qwertyfly...

    Scripting Gradient Stops

    MrJHMaximus Level 1

      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[i].fillColor.typename == 'GradientColor' ) {
          var theStops = paths[i].fillColor.gradient.gradientStops;
          for (j=0; j< theStops.length; j++) {
                  var valGradOp = theStops[j].opacity
                  var valGradTint = theStops[j].color.tint
                    if (theStops[j].color.tint == valGradTint && theStops[j].opacity == valGradOp){  
                         theStops[j].color.tint = valGradOp;  
                         theStops[j].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[j].color.typename == "RGBColor") {  
                  if (Math.round(theStops[j].fillColor.red) == 255 &&  
                  Math.round(theStops[j].fillColor.green) == 255 &&  
                  Math.round(theStops[j].fillColor.blue) == 255 &&
                  Math.round(theStops[j].opacity) == 100.0) { 
                  theStops[j].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!