3 Replies Latest reply on Aug 19, 2016 12:54 PM by Silly-V

    Changing the strokeWidth using strokeColor


      I'm new to JavaScript, and I'm having some difficulty.  I've got some existing knowledge of python, but I've found it's rather different.  I'm trying to figure out how to change the stroke width for a path based on it's color.  There is a simplified version of my script below.


      For some reason it never recognizes the color of the path.  I've tried comparing the color class I created with the stroke color, but that never works.  I've also tried doing a comparison of all the different RGB components of the color, but that gives me an error.  If I add path.strokeColor.RGBColor.red I get an error saying that "undefined is not an object". 


      The RGB color class should have a red component, right?  I don't understand why it's undefined.


      Does anybody have any thoughts?


      if (documents.length > 0 && activeDocument.pathItems.length > 0){
        // Gets all the paths in the document
        var allPaths = activeDocument.pathItems;
        // This is the color I want to find, red
        var red = new RGBColor();
        red.red = 233;
        red.green = 38;
        red.blue = 41;
        // Change the stroke of the path if it's a red line
        for (var l=0; l < allPaths.length; l++) {
        // select only red paths
        if (allPaths[l].strokeColor.RGBColor.red == red.red) {
        allPaths[l].strokeWidth = 10.0;
        • 1. Re: Changing the strokeWidth using strokeColor
          Silly-V Adobe Community Professional

          In this case of javascript, the "RGBColor" is actually the "strokeColor".

          So you can just do:

          if (allPaths[l].strokeColor.red == red.red) { 

          3 people found this helpful
          • 2. Re: Changing the strokeWidth using strokeColor
            dennis.e Level 1

            That fixed it!  The way the illustrator reference scripts are written I thought that RGBColor was a subclass or property of the Color class.  I wouldn't have thought that they might be the same.  I was getting really frustrated trying to figure it out.


            Thank you.

            • 3. Re: Changing the strokeWidth using strokeColor
              Silly-V Adobe Community Professional

              Well, the RGBColor is a color, but when referenced, it does not get explicitly accessed like that. I am also not sure how a professional javascript scientist would described this, but a parallel example would be with pageItems and pathItems: if you have only one path (could be a rectangle or just a line) you can refer to it as activeDocument.pageItems[0] or activeDocument.pathItems[0], but it does not work if you try to do activeDocument.pageItems[0].pathItems[0] - because both pageItems[0] and pathItems[0] refer to the same object, while one is a super-class of the other. (pageItems is a super-class and pathItems is a subset of that).