7 Replies Latest reply on Feb 28, 2015 10:02 AM by Kai Rübsamen

    linked text frame in enumeration

    hamdifem Level 1

      in one document there are many embedded text frame (object style applied = "myObjSty1")

      I want to write increasing numbers

      I tried to write but did not

      Can you help me in this regard

      Thank you in advance


      var sNo = 1;
      var doc = app.activeDocument;  
      app.findGrepPreferences = app.changeGrepPreferences = null;  
      app.findGrepPreferences.findWhat = "~a";  
      var found = doc.findGrep();  
      for(var i =found.length-1;i>=0;i--)
      if(found[i].allPageItems[0].appliedObjectStyle == myObjSty1)
           app.changeGrepPreferences.changeTo = (++sNo);
        • 1. Re: linked text frame in enumeration
          Laubender Adobe Community Professional & MVP

          @handifem – you made several assumptions here not spoken out, when I am looking at your code (and reading about what you are trying to accomplish here). I might be wrong, but:


          What kind of sequence would you like to see?


          Order of anchored text frames in one single story?

          That would be: myStory.textFrames by their index numbers.

          Geometrical order throughout the story depending on their position on the page?

          Throughout the document?

          Something else?


          A GREP Search with "~a" may find the anchors representing the anchored text frames in a totally different order you would like to see.


          If we know something more, I think, we can help with the code as well.



          • 2. Re: linked text frame in enumeration
            hamdifem Level 1

            Text in the fluid

            anchored text frame (and applied them to the object style)

            in which "1" is writing. delete "1"

            to enumerate them, respectively,



            • 3. Re: linked text frame in enumeration
              Laubender Adobe Community Professional & MVP

              @handifem – ah, ok. This is the easy case of sequence.

              You need no GREP search for this, simply iterate through all text frames of the story.


              Here an example where I assume, that are no other text frames anchored to the story that would not need numbering:


              var myStory = app.selection[0].parentStory;
              var myAnchoredTextFrames = myStory.textFrames.everyItem().getElements();
              for(var n=0;n<myAnchoredTextFrames.length;n++){
                  myAnchoredTextFrames[n].texts[0].contents = String(n+1);


              Of course you could decorate it with an if clause to single out all text frames with a specific object style.



              • 4. Re: linked text frame in enumeration
                hamdifem Level 1

                I could not connect to an object style

                To enumerate all frames


                var myStory = app.selection[0].parentStory; 

                var myAnchoredTextFrames = myStory.textFrames.everyItem().getElements(); 

                if(myAnchoredTextFrames.appliedObjectStyle == myObjSty1){ //?

                for(var n=0;n<myAnchoredTextFrames.length;n++){ 

                    myAnchoredTextFrames[n].texts[0].contents = String(n+1); 



                • 5. Re: linked text frame in enumeration
                  Laubender Adobe Community Professional & MVP

                  1. You have to set the if clause inside the for loop.

                  2. You need to address every single text frame by its index

                  3. You need a counter to advance every time a match is found


                  //Object style is named "MyObjectStyle1"
                  //It is not nested in an ObjectStyleGroup !!
                  var myObjSty1 = app.documents[0].objectStyles.itemByName("MyObjectStyle1");
                  //Selection is the text frame or some text of the story you want to get the anchored text frames:
                  var myStory = app.selection[0].parentStory;
                  //Collecting ALL anchored text frames of the story to an array:
                  var myAnchoredTextFrames = myStory.textFrames.everyItem().getElements();
                  //Define a start number:
                  var myStartNumber = 1;
                  //Loop through the array of the text frames anchored:
                  for(var n=0;n<myAnchoredTextFrames.length;n++){
                      //If my object style is assigned to the individual anchored text frame in that array:
                      if(myAnchoredTextFrames[n].appliedObjectStyle == myObjSty1){
                          //Set the contents to its text to the String of the current value of the start number variable
                          myAnchoredTextFrames[n].texts[0].contents = String(myStartNumber);
                          //If that is done, change the current number by adding the number 1:
                          myStartNumber = myStartNumber + 1;




                  PS.: You should really look more into the basics for JavaScript before doing more work in ExtendScript.

                  • 6. Re: linked text frame in enumeration
                    Kai Rübsamen Level 4

                    Hi Guys,


                    although this seems to be answered a idea for a nonscripting way:


                    1. Create a paragraph style with autonumbering in a separate textframe with Autosize > width only.

                    2. Insert your textframe with the numbers

                    3. Write your text, add or delete some numbers, half way done


                    4. You will maybe discover a problem, that is shown in my screenshot. Sometimes the textframes and the followed character are overlapping. I think this is a bug.

                    5. Solution: Create a shortcut for "Recompose all stories immediately". After refreshing the document everything is fine, so no script needed








                    • 7. Re: linked text frame in enumeration
                      Kai Rübsamen Level 4

                      After a further test: It seems that 'recompose' is not necessary, if the textframes column have a fixed width (to hold 2 or 3 numbers) and 'Autosize' is turned off.

                      Bildschirmfoto 2015-02-28 um 19.01.36.png