11 Replies Latest reply on Jun 20, 2016 5:24 AM by Johnwhite

    How to get anchor text into story?

    Johnwhite Level 1

      Hi experts,

       

      is that possible to get the anchor text, like this:

       

      0001.jpg

       

      and get the text and then place it into text frame, like this:

       

      0002.jpg

       

      thanks

      regard

      John

        • 1. Re: How to get anchor text into story?
          vinothr Level 3

          Should be simple....

           

          Just select the text anchor frame and run the following script....

           

          var tf = app.selection[0];
          
          if(tf.parent.constructor instanceof Character) {
            tf.texts.everyItem().move(LocationOptions.BEFORE, tf.parent);
            tf.parent.contents = "\r";
          }
          
          • 2. Re: How to get anchor text into story?
            Johnwhite Level 1

            Thank you Vinothr

            thank you for your help.

            but I have thousand of anchor, so if there is a constructor for anchor to define?

             

            regard

            John

            • 3. Re: How to get anchor text into story?
              Johnwhite Level 1

              Hi experts,

               

              How define anchor object like this:

               

              var tf = app.textFrames.anchoredObject;   
              
              if(tf.parent.constructor instanceof Character) {   
                tf.texts.everyItem().move(LocationOptions.BEFORE, tf.parent);   
                tf.parent.contents = "\r";   
              } 
              

              how to make it working?

               

              thanks

              regard

              John

              • 4. Re: How to get anchor text into story?
                Laubender Adobe Community Professional & MVP

                Hello John,

                take your view off the anchored text frame itself, direct your attention to the story object.

                Then ask the story object how many text frames are in the story.

                 

                For example select the text frame of your main thread of text frames in the document and run this snippet:

                 

                app.selection[0].parentStory.textFrames.everyItem().getElements().length;
                

                 

                Then do the same with the document and with all of its stories:

                 

                app.documents[0].stories.everyItem().textFrames.everyItem().getElements().length;
                

                 

                Remove .length from the code and run the snippets again.

                Test again. Add .constructor.name instead of .length and test again.

                 

                What does the JavaScript Console of your ESTK return?

                I hope, that keeps you running.

                 

                Uwe

                • 5. Re: How to get anchor text into story?
                  Johnwhite Level 1

                  Hi Uwe

                   

                  both nothing return.

                   

                  thanks

                  regard

                  John

                  • 6. Re: How to get anchor text into story?
                    Laubender Adobe Community Professional & MVP

                    Nothing? Did you run the snippet from the ESTK (ExtendScript Toolkit)?

                    Or: 0 ?

                     

                    If the snippet was run from the ESTK, returned "0" and without seeing the document, I can only assume, that:

                    1. There are no anchored text frames objects in your stories at first level (they may be nested) or that:

                    2. All of your anchored text frames are anchored to table cells.

                    3. The anchored text frames are anchored in footnote texts.

                     

                    Some cases:

                     

                    1-Cases-AnchoredTextFrames.png

                     

                    Wrap an alert around the snippet and run it again:

                     

                    2-Cases-AnchoredTextFrames-Alert-TextFramesInStory.png

                     

                    What is your version of InDesign?
                    What is your OS?

                     

                    Uwe

                    • 7. Re: How to get anchor text into story?
                      Johnwhite Level 1

                      Hi Uwe,

                       

                      First I selected the main story, then run the script as yours, I got the result.

                       

                      but How can I get the anchor text into story now?

                       

                      So, how can I make this working?

                       

                      var tf = app.documents[0].stories.everyItem().textFrames.everyItem().getElements().length;      
                        
                      if(tf.parent.constructor instanceof Character) {      
                        tf.texts.everyItem().move(LocationOptions.BEFORE, tf.parent);      
                        tf.parent.contents = "\r";      
                      }
                      

                       

                      thanks

                      Regard

                       

                      John

                      • 8. Re: How to get anchor text into story?
                        Laubender Adobe Community Professional & MVP

                        With my snippet you have access to an array of text frames, that represent your anchored ones.

                        That's var result, if you cut off .length like I already suggested. Or in you recent code snippet, that's var tf .

                         

                        Loop through that array in reverse order, move the texts out and—optional*—replace the contents of the parent of the text frame with a return sign. You will find plenty of examples here in the scripting forum using for loops, that are looping in reverse order.

                         

                        *Note: Simply replacing the anchored text frame with a paragraph sign is no good idea, because the formatting of the paragraph sign and the moved text could be different. Depending on the used paragraph styles, text formatting overrides can happen:

                         

                        Before replacement:

                         

                        3-BeforeReplacing-FormattedTextPlusParagraphSign.png

                         

                        After replacement.

                        The paragraph sign will not fit the formatting of the paragraph. Here in my example there are different font weights, point sizes and language settings.

                         

                        4-AfterReplacing-FormattedTextPlusParagraphSign-OnceWasTextFrame.png

                         

                        And that's usually no good idea.

                        In your very special case, this perhaps plays no role, but often text in anchored txt frames is formatted differently from the text where they are anchored with.

                         

                        Regards,
                        Uwe

                        • 9. Re: How to get anchor text into story?
                          Johnwhite Level 1

                          Hi Uwe,

                           

                          What I want just get the anchor text into the main story, we can ignore the anchor text format.

                           

                          regard

                          John

                          • 10. Re: How to get anchor text into story?
                            Ravindra_KCS Level 1

                            Hi John,

                               As I understanding ur issue,  Try this....

                             

                            var myDocument = app.activeDocument;

                            app.findObjectPreferences = NothingEnum.nothing;

                            app.changeObjectPreferences = NothingEnum.nothing;

                            app.findObjectPreferences.anchoredPosition = AnchorPosition.ANCHORED;

                             

                            var t  =myDocument.findObject();

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

                            {

                                    var tf=t[i];

                                    if(tf.parent.constructor instanceof Character)

                                    {       

                                      tf.texts.everyItem().move(LocationOptions.BEFORE, tf.parent);       

                                      tf.parent.contents = "\r";       

                                    } 

                            }

                             

                            Thanks and Regards

                            Ravindra

                            1 person found this helpful
                            • 11. Re: How to get anchor text into story?
                              Johnwhite Level 1

                              Thank you Ravindra

                               

                              Yes, my goal like this.

                               

                              thank so mych.

                               

                              Regard

                              John