4 Replies Latest reply on Mar 7, 2013 12:04 PM by DuanesSearchForKnowledge

    changing the color of text frames on only the active layer

    DuanesSearchForKnowledge Level 1

      Okay my script to change text frame color changes the color of all text frames hidden or not.

      I need it to only change visible text frames.

       

      if ( app.documents.length > 0 ) {

      newCMYKColor = new CMYKColor();

      newCMYKColor.black = 0;

      newCMYKColor.cyan = 0;

      newCMYKColor.magenta = 0;

      newCMYKColor.yellow = 0;

       

      for ( i = 0; i< app.activeDocument.textFrames.length; i++) {

      textArtRange = app.activeDocument.textFrames[i].textRange;

      textArtRange.characterAttributes.fillColor = newCMYKColor;

      }

      }

       

      Any ideas on how to go about making it only change the color of text frames on the active layer? In the final script I will hide all other layers so if it could be done by a visible attribute more easily that would work just as well.

       

       

      Thanks,

      Duane Leach

        • 1. Re: changing the color of text frames on only the active layer
          klemango Level 1

          Hello,

          Will this work for you?  Haven't tested it much beyond text frames in groups and those that are just stand-alone on the layer.

           

           

           

          if (app.documents.length > 0){

           

          var thisDoc = app.activeDocument;

           

          newCMYKColor = new CMYKColor();

          newCMYKColor.black = 00;

          newCMYKColor.cyan = 40;

          newCMYKColor.magenta = 50;

          newCMYKColor.yellow = 50;

           

           

          //  Need to grab the text frames from within the groups on the layer.

          var artSel = thisDoc.activeLayer.groupItems;

           

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

                  if (artSel[i].hidden == false){

                  var text = artSel[i].textFrames;

                      for (j=0;j<text.length;j++)

                          text[j].textRange.characterAttributes.fillColor = newCMYKColor; 

                          }

              }

           

          //  Finish changing the rest of the text frames outside of groups.

          var textArtRange = app.activeDocument.activeLayer.textFrames;

              for (k=0;k<textArtRange.length;k++)

                  if(textArtRange[k].hidden == false)

                  textArtRange[k].textRange.characterAttributes.fillColor = newCMYKColor

          }

          else

          alert("There isn't any open documents to change...");

          • 2. Re: changing the color of text frames on only the active layer
            DuanesSearchForKnowledge Level 1

            This worked flawlessly until I ran across a file with text group inside another group. Then it did not change the color of the text frame.

             

            Would I have to make another variable: var artSel = thisDoc.activeLayer.groupItems.groupItems; to catch those text frames?

             

            Another thought, is there a way to ungroup all groups on a layer before trying to change the text frames?

             

            Thanks for the reply,

             

            Duane

            • 3. Re: changing the color of text frames on only the active layer
              klemango Level 1

              Sorry Duane by not getting back to you sooner.  I'm traveling from MO to PA right now and haven't had a chance to look at this.  (I'm on my wife's laptop now and she has no need for Illustrator, so I don't have the SDK to do any testing).  If you don't get an answer from anyone in the forum, I'll look at it as soon as I get to PA and have my OWN laptop back).

               

              I ran into that group problem when I first wrote the script to change the text on the active layer, so I put the statement(s) with the groups in there, but I didn't think about more text groups nested within other groups and never tested for that issue. 

               

              If groups are not a concern with your needs, then the post I read where Carlos commented about moving the items in the group(s) to the beginning or end of the active layer before changing the text would be the first thing to do, then just include the loop to change each textFrame on the activeLayer.

              • 4. Re: changing the color of text frames on only the active layer
                DuanesSearchForKnowledge Level 1

                klemango,

                 

                Thanks for getting back with me and yes Carlos's examples of moving pageitems out of groups helped a lot. Now the example you showed me is getting almost all the textframes. I only have to find a way to loop through till there are no more groups because there will be times i will have groups within groups within groups...

                 

                 

                Thank you,

                Duane