16 Replies Latest reply on Dec 6, 2012 2:20 AM by Laubender

    All anchored textframes in a document

    vDeepak

      Hello,

       

      I want to get all anchored textframes present in a document. Does anybody know how to get it?

       

      Thanks and Regards.

        • 1. Re: All anchored textframes in a document
          Vamitul Level 4

          to get them how?

          doc.stories.everyItem().textFrames.everyItem() should get you there (I think?!)

          • 2. Re: All anchored textframes in a document
            Cenchen Level 2

            Try this,

             

             

            var doc = app.activeDocument;

            app.findObjectPreferences = app.changeObjectPreferences = null;

            app.changeObjectPreferences = app.findObjectPreferences = null;

            app.findChangeObjectOptions.objectType  = ObjectTypes.TEXT_FRAMES_TYPE

            var tf = doc.findObject();

            var anch = []

            for(var i=0;i<tf.length;i++)

            {

                    try

                    {

                            doc.select(tf[i])

                            var myAnchor = app.selection[0]

                            var myAnchorPosition = myAnchor.anchoredObjectSettings.anchoredPosition;

                            if(myAnchorPosition.toString().match("ANCHORED","i"))

                            {

                                anch.push(tf[i])

                             }

                        }

                        catch(e){}

                 }

            alert(anch)

            1 person found this helpful
            • 3. Re: All anchored textframes in a document
              Vamitul Level 4

              instead of selecting the frame, and checking, you can simply use:

               

              tf[i].parent.constructor.name=="Character"

               

              since the parent of a anchor is a character object.

              1 person found this helpful
              • 4. Re: All anchored textframes in a document
                vDeepak Level 1

                Thanks, Vamitul. It works fine.

                 

                @Cenchen - Thanks for your reply.

                • 5. Re: All anchored textframes in a document
                  Harbs. Level 6

                  That works for anchors in regular text. For footnotes you need this:

                  doc.stories.everyItem().footnotes.everyItem().textFrames.everyItem()

                   

                  For tables you'll need something like this:

                  doc.stories.everyItem().tables.everyItem().cells.everyItem().texts.everyItem().textFrames. everyItem()

                  • 6. Re: All anchored textframes in a document
                    TᴀW Adobe Community Professional & MVP

                    Probably won't work for nested tables though

                     

                    Ariel

                    • 8. Re: All anchored textframes in a document
                      [Jongware] Most Valuable Participant

                      Arïel wrote:

                      Probably won't work for nested tables though

                       

                      This will, admittedly in kind of a roundabout way. I tested with anchored objects inside anchored objects, anchored objects inside a table, anchored objects inside a table inside a table, and anchored objects inside footnotes.

                       

                      all = app.activeDocument.stories.everyItem().texts.everyItem().getElements();
                      i = all.length-1;
                      while (i >= 0)
                      {
                        if (!(all[i].parentTextFrames[0].parent instanceof Character))
                          all.splice(i,1);
                        i--;
                      }
                      alert (all.length);
                      

                       

                      True, it could be done with looping over every story and all and any object therein (verily, unto the second and third generation, etc.), but I'm pretty sure this way you cannot ever ever skip an anchored object just because it's inside a table inside a footnote inside an anchored object.

                       

                      .. I didn't actually test that last scenario. Should I?

                       

                      Message was edited by: [Jongware] What up with the automatic tab-to-5 spaces conversion? Can't that be decreased by anyone to a *reasonable* value?

                      • 9. Re: All anchored textframes in a document
                        [Jongware] Most Valuable Participant

                        <g> I though it would be easier if I just iterate over 'allTextFrames'. Well, it ain't there so you have to use 'allPageItems' instead. (It would need an additional check for "TextFrame" but I could live with that.)

                         

                        However, I suddenly get one more frame reported! Mystery & frustration &c., so I inserted a line to have text frames tell what number they think they are:

                         

                        all = app.activeDocument.allPageItems;
                        alert (all.length);
                        
                        i = all.length-1;
                        while (i >= 0)
                        {
                          if (!(all[i].parent instanceof Character))
                            all.splice(i,1);
                          i--;
                        }
                        alert (all.length);
                        for (i=0; i<all.length; i++)
                        {
                          all[i].words[0].contents = "[I Am Frame #"+String(i)+"]";
                        }
                        

                         

                        ... and a single one frame inside a nested table suddenly declares: "[I Am Frame #7] Am Frame #6]" ...

                        Any eagle-eyed coders know why that would happen?

                        • 10. Re: All anchored textframes in a document
                          Laubender Adobe Community Professional & MVP

                          @Harbs – we could also look for all anchored objects with

                           

                          TEXT search with:

                          " <FFFC> "  or:  " ^a "


                          or GREP search with:

                          " \x{FFFC} "  or:  " ~a "

                           

                          and check the texts object for text frames of every individual element of the result:

                           

                          var mySearchString = "<FFFC>";
                          var myAnchoredTextFramesIDs = new Array();
                          var myResult, n, counter;
                          
                          app.findTextPreferences = app.changeTextPreferences = null;
                          
                          app.findTextPreferences.findWhat = mySearchString;
                          
                          myResult = app.activeDocument.findText();
                          
                          app.findTextPreferences = app.changeTextPreferences = null;
                          
                          counter = 0;
                          
                          for(n = myResult.length-1; n >= 0; n--){
                          
                              if(myResult[n].texts[0].textFrames.length == 1){
                          
                                   //EXAMPLE: How to get the ID of the anchored text frame for later use:
                                   myAnchoredTextFramesIDs[counter] = myResult[n].texts[0].textFrames[0].id;
                                   ++counter;
                                   };
                          
                               };
                          

                           

                           

                          That will also find all anchored text frames in every nested table.

                           

                          Uwe

                           

                          Message was edited by: Laubender

                          • 11. Re: All anchored textframes in a document
                            Vamitul Level 4

                            whooo...

                            you tell me you can have anchored objects in footnotes?? yet still no damn footnotes in tables?!!

                            • 12. Re: All anchored textframes in a document
                              Laubender Adobe Community Professional & MVP

                              you can have anchored objects in footnotes??

                               

                              @Vamitul – of course you can. And with my script in #10 you can find them and single out the text frames…

                               

                              Uwe

                              • 13. Re: All anchored textframes in a document
                                Harbs. Level 6

                                Yup. That's probably the best way, although it might not be the fastest on really complex documents...

                                • 14. Re: All anchored textframes in a document
                                  Vamitul Level 4

                                  @uwe

                                  var mySearchString = "<FFFC>";

                                  var myAnchoredTextFramesIDs = new Array();

                                  var myResult, n, counter;  

                                  app.findTextPreferences = app.changeTextPreferences = null;

                                  app.find.FindChangeTextOption.includeFootnotes=false;

                                   

                                  app.findTextPreferences.findWhat = mySearchString; 

                                  myResult = app.activeDocument.findText(); 

                                  app.findTextPreferences = app.changeTextPreferences = null; 

                                  counter = 0;  

                                  for(n = myResult.length-1; n >= 0; n--)

                                  {       if(myResult[n].texts[0].textFrames.length == 1)

                                  {            //EXAMPLE: How to get the ID of the anchored text frame for later use:   

                                        myAnchoredTextFramesIDs[counter] = myResult[n].texts[0].textFrames[0].id;

                                            ++counter;          };

                                         };

                                  now it won't... I HATE hearing the words Indesign and footnotes in the same sentence..

                                   

                                  • 15. Re: All anchored textframes in a document
                                    Peter Kahrel Adobe Community Professional & MVP

                                    > app.find.FindChangeTextOption.includeFootnotes=false;

                                     

                                    make that

                                     

                                    app.findChangeTextOption.includeFootnotes=false;

                                     

                                    By the way, it's probably safer to search for ^a/~a. Maybe <FFFC> is used for other things as well, similar to <FEFF>, which is used for page references and tags.

                                     

                                    Peter

                                    • 16. Re: All anchored textframes in a document
                                      Laubender Adobe Community Professional & MVP

                                      @Peter – good point.
                                      And if <FFFC> is not used now for other things (I'm not aware that it is), maybe it's used for different things in future versions of InDesign.

                                       

                                      Uwe