Trying to work a script that:

  1. Select ALL/EVERYTHING with gradient on fill or stroke (texts, shapes, linestrokes, paths - objects, etc)
  2. Replace ALL those gradient fills OR gradient strokes with: Fill Color green #00FF00 & Stroke Color pink #FF1D8E

Second 2. part of setting to the green fill color I've figured out but having lot of problems getting a script to identify and select ALL gradients used on the document through all kind of elements.

This is my NOT WORKING code for the gradient to flat FILL only because haven't started the stroke part since im not being able to make the fill work yet).

    // Single Fill Color All Gradients

    if ( app.documents.length > 0 && app.activeDocument.pathItems.length > 0) 
        if(app.activeDocument.documentColorSpace == DocumentColorSpace.RGB)
    }//end main if 

    function gradientToFillColor() {            
        var greenColorFinal;
        var items = selection;
        var totalSelected = items.length;
        if(totalSelected > 0)

            for(var c=0; c < totalSelected; c++)
                var currentObject = app.activeDocument.selection[c];
                if(currentObject.typename != "CompoundPathItem" && 
                   currentObject.typename != "GroupItem")
                    if(currentObject.filled == true && 
                       currentObject.fillColor.typename != "RGBColor" && 
                       currentObject.fillColor.typename != "PatternColor" && 
                       currentObject.fillColor.typename != "SpotColor")

                        var currentColor = currentObject.fillColor;
                        var gradientSpectrum = currentColor.gradient.length;
                        var colorGradient=[];                   

                        for(var g=0; g < gradientSpectrum; g++)
                            colorGradient[g] = currentColor.gradient[g].color;
                            if(colorGradient[g].typename = "RGBColor" &&
                               colorGradient[g].typename = "PatternColor" &&
                               colorGradient[g].typename = "SpotColor")
                                currentObject.fillColor ="Color").setValue([0,255,0,0]);

                        }//end for g



            }//end for c


  • Please share what you have tried. – Scott Dec 6 at 22:44
  • hey scott, thanks for the recommendation. posted it above. – Dec 7 at 10:59

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.