5 Replies Latest reply on Jan 20, 2015 1:27 PM by Laubender

    textFrames in Page class does not includes the groupped ones

    buraktamturk

      Hello,

       

      We want to find text frames that has object style "X" in all pages. So far, we wrote this.

       

      [code]

      function paragraphByNesneStilWp(stil) {

          var tests = [], i, j, it, p, buldu, d = myDoc;

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

              p = d.pages.item(i);

              if(p && p.isValid) {

                  pi = p.textFrames;

                  buldu = false;

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

                      it = pi[j];

                      if(it && it.appliedObjectStyle == stil) {

                          buldu = true;

                          tests.push({pr: it, sn: i});

                          break;

                      }

                  }

       

                  if(!buldu) {

                      pi = p.masterPageItems;

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

                          it = pi[j];

                          try {

                          if(it && it.appliedObjectStyle == stil) {

                              tests.push({pr: it.override(p), sn: i});

                              break;

                          }

                      } catch(e){}

                      }

                  }

              }

          }

          return tests;

      }

      [/code]

       

      The input parameter of this function "stil" is the object style. We are using this function like this.

       

      [code]

      function os(a) {

          var x, i;

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

              if(i == a.length - 1) {

                  x = (x ? x : app.activeDocument).objectStyles.item(a[i]);

                  if(!x || !x.isValid) return null;

              } else {

                  x = (x ? x : app.activeDocument).objectStyleGroups.itemByName(a[i]);

                  if(!x || !x.isValid) return null;

              }

          }

          return x.isValid ? x : null;

      }

       

      var stil = os(["TEST", "TEST 1"]);

      var questions = paragraphByNesneStilWp(stil);

       

      alert("There is " + questions.length + " question in this document");

      [/code]

       

       

      This function returns all of the textframes in all pages that object style is stil (and if it included in the master, it also overrides it).

       

      So far it's working great (like everyone at here ) except it does not count the textframe when it is groupped with another object (the style is applied the textframe not the group itself).

       

      Is there anybody that can help me modifying this script? so it can count the groupped ones.

       

      Thank you,

      Burak

        • 2. Re: textFrames in Page class does not includes the groupped ones
          buraktamturk Level 1

          I've replaced both of the "if(it && it.appliedObjectStyle == stil) {" to "if(it && it.appliedObjectStyle.name == stil.name) {" but the script is acting same, what i'm missing here?

           

          Edit: Opps. I now understant it, let me try the script that you provided to me again.

          • 3. Re: Re: textFrames in Page class does not includes the groupped ones
            Sajeev Sridharan Level 4

            I saw the previous discussion which Chinna mentioned in this post,

             

            Try this, this will help you to sort out the group object issue:

             

            var doc = app.activeDocument;  
            var myBox = doc.allPageItems;  
            for(var i=0;i<myBox.length;i++)  
            {  
                if(myBox[i] instanceof TextFrame)  
                {  
                        if(myBox[i].appliedObjectStyle.name == "myStyle01")  
                        {  
                                app.findGrepPreferences = app.changeGrepPreferences = null;   
                                app.findGrepPreferences.findWhat = "A";   
                                app.findGrepPreferences.fillColor = "Color01";  
                                app.changeGrepPreferences.changeTo  = "X";   
                                try{
                                    myBox[i].lines[0].texts[0].changeGrep();   
                                }catch(e){}
                                app.findGrepPreferences = app.changeGrepPreferences = null;  
                            }  
                }  
                else if(myBox[i] instanceof Group)  
                {  
                        if(myBox[i].appliedObjectStyle.name == "myStyle01")  
                        {  
                            app.findGrepPreferences = app.changeGrepPreferences = null;   
                            app.findGrepPreferences.findWhat = "A";   
                            app.findGrepPreferences.fillColor = "Color01";  
                            app.changeGrepPreferences.changeTo  = "X";   
                            for(var j=0; j<myBox[i].textFrames.length; j++)
                            {
                                try{
                                    myBox[i].textFrames[j].lines[0].texts[0].select();
                                    app.selection[0].changeGrep();   
                                }catch(e){}
                            }
                            app.findGrepPreferences = app.changeGrepPreferences = null;  
                        }  
                    }  
            }  
            

             

             

            Vandy

            • 4. Re: textFrames in Page class does not includes the groupped ones
              buraktamturk Level 1

              Yes, i missed this point there, now fixed it. the "instanceof" thing and the "allPageItems" was the key of the solution.

               

              Thank all of you.

              • 5. Re: textFrames in Page class does not includes the groupped ones
                Laubender Adobe Community Professional & MVP

                @buraktamturk – A different solution would be to iterate through the textContainers arrays of all stories of a document. TextContainers by definition are arrays of TextFrames or TextPaths objects. That would minimize the objects you have to visit and should increase speed.

                 

                That would also work for objects (textFrames) that are not available in the array myDocument.allPageItems.

                 

                Uwe