27 Replies Latest reply on Mar 4, 2015 9:18 PM by suneetha.s

    Find threaded text frames in document

    suneetha.s

      Hi All,

       

      I have created document with 30 pages, It contains both threaded textframes and un-threaded textframes. I have to write scripting tool to find the un threaded text frames and anchor them to next frame to flow with the content.

       

      Any help will be greatly appreciated.

       

      Thanks in advance

        • 1. Re: Find threaded text frames in document
          Peter Spier Most Valuable Participant (Moderator)

          moved to the scripting forum...

          • 2. Re: Find threaded text frames in document
            Jump_Over Level 5

            suneetha.s napisał(-a):

             

            ...I have to write scripting tool...

             

            Hi,

            Did you write any part? Did any particular problem stop you?

             

            Jarek

            • 3. Re: Find threaded text frames in document
              suneetha.s Level 1

              Hi Jarek,

               

              I'm done with other part of scripting, but to continue further I need to know how to check unthreaded text frames in the document.

               

              Please find the screen shots below for more details on the issue i'm working on.

              Un-ThreadedTF.png

               

              The document have multiple text frames. And in the example screen shot you can notice the text is flowing from first page to second page.

               

              In first page we have 3 text frames. 1 text frame has the content and next two text frames are graphic and caption (i.e. Graphic text frame & Text frame)

               

              Now I have to write script to find the un-threaded text frames in the document and anchor them to before or after textframes.

               

              Ex: The first Graphic frame (Unthreaded text frame 1) should anchor to end Insertion point of Learning objectives text frame and the next Text frame (Unthreaded text frame 2) should anchor next to graphic frame .

              • 4. Re: Find threaded text frames in document
                Jump_Over Level 5

                Hi,

                 

                There is many ways to detect unthreated textFrame. One of them is to check if textFrame.parentStory.textContainers.length == 1

                 

                However described goal looks like much more complex and involves many questions:

                1. what do you mean by "graphic text frame"?

                2. could one page have more threated textFrames than one?

                3. could your doc have more threated stories than one?

                4. could any threated textFrame be empty (i.e. text overflown)?

                5. could your doc have many layers?

                6. what about other objects (graphic lines, polyghons)?

                ....

                 

                Some answers could involve more questions.

                 

                In case of anchoring object ==> you can not move them (if found) into chosen insertionPoint.

                You have to recreate them or place them in this location.

                So solution could be to temporary export proper object as snippet and place them with calculated achoredObjectSettings

                 

                Maybe easier is to reconsider your goal ... ?

                 

                Jarek

                • 5. Re: Find threaded text frames in document
                  suneetha.s Level 1

                  Hi,

                   

                  Thanks for the quick response..

                   

                  Yes my goal is much complex and this is small portion of it.

                  please find the below my answer to your questions

                   

                  1. The graphic text frame is nothing but Rectangle Frame with graphic content. where the images are being placed.(you can find image in first page).

                   

                  2. Yes, since it's two column template the two text frames threaded each and if in case page contains table's or Images in separate text frames we have to thread them to make flow content.

                   

                  3. Yes, it will have separate stories

                   

                  4. No, document doesn't have empty frames.

                   

                  5. No, document created with single layer

                   

                  6. Yes, document has other objects too like polygon, graphic lines.

                   

                  Yes, if i found the before or after textframes insertion points it's easier to place and anchoring the object.

                  But before anchoring objects, I should find the textframes which exist before.

                   

                  //finding the textframe insertion point.

                  var doc = app.activeDocument; 

                  var insertionPoint= doc.pages[n].textFrames[n].insertionPoints.item(-1)

                   

                  //set object anchor point to that textframe

                  var graphics = doc.allGraphics; 

                  graphics[0].parent.anchoredObjectSettings.insertAnchoredObject(insertionPoint, AnchorPosition.ANCHORED)

                   

                  So now after finding un-threaded textframe, How to find the textframe which exist before the un-threaded textframe?

                   

                  I also checked with the pageItems, but this will not give an order like textframe1, textframe2 ... textframe n.

                  var items =  doc.pages[0].pageItems;

                   

                  Awaiting for your reply.

                   

                  Thanks in advance :-)

                  • 6. Re: Find threaded text frames in document
                    Jump_Over Level 5

                    Hi,

                     

                    Basicly reflect which output are you going to reach:

                    input.jpg

                    output.jpg

                    Jarek

                    • 7. Re: Find threaded text frames in document
                      suneetha.s Level 1

                      Hi,

                       

                      Yes, the expected output would be OUTPUT 2.

                       

                      As explained in previous conversation, In the first page I have Graphic Rectangle and Textframe with fig caption. Both are have not threated. since the Figure caption should display under Graphic rectangle, cannot be threated with First and next page textframes. So the output1 might not meet our requirement.

                       

                      Thanking you

                       

                      suneetha

                      • 8. Re: Find threaded text frames in document
                        Jump_Over Level 5

                        Hi,

                        So we've got 3 steps:

                        • to group all page items except threated textFrames
                        • to export it as a snippet (temporary)
                        • to place it as anchored object with calculated properties (no matter which insertionPoint - set anchor relation to page edge)

                         

                        which step stops you?

                         

                        Jarek

                        • 9. Re: Find threaded text frames in document
                          suneetha.s Level 1

                          Hi,

                           

                          Yes exactly !

                           

                          I'm in step three, I have to find  previous textframe or object of un-threaded textframe and place anchored object.

                           

                          So, In my example screen shot you can find in first page, the previous textframe of an Graphic rectangle is "Learning objectives".

                           

                          Thanks,

                          suneetha

                          • 10. Re: Find threaded text frames in document
                            Laubender Adobe Community Professional & MVP

                            In case of anchoring object ==> you can not move them (if found) into chosen insertionPoint.

                             

                            to export it as a snippet (temporary)

                             

                            @Jarek – I did not read all of this thread thoroughly, but if you like to anchor any plain object on a spread (not grouped or nested otherwise) to a insertion point, you can use a method that is with us since InDesign CS5.5:

                             

                            insertAnchoredObject(argument1,argument2)

                             

                            For that we need:

                            1. The page item we want to anchor (myPageItem), its anchoredObjectSettings

                            2. The insertion point (myInsertionPoint) will be argument 1 of the method

                            3. The kind of anchor position like AnchorPosition.ANCHORED or ABOVE_LINE or INLINE_POSITION will be argument 2 of the method (optional)

                             

                            myPageItem.anchoredObjectSettings.insertAnchoredObject(myInsertionPoint, AnchorPosition.ANCHORED);
                            

                             

                            myPageItem could even be positioned on a different spread, but of course it will be moved to the spread where the text frame that is holding the insertionPoint is positioned.

                             

                            Adobe InDesign CS6 (8.0) Object Model JS: AnchoredObjectSetting

                             

                            Note: The link "Browse online" below the CS5.5 DOM documentation is showing the CS5 DOM where this method is not available.

                             

                            Uwe

                            • 11. Re: Find threaded text frames in document
                              Jump_Over Level 5

                              Hi Uwe,

                               

                              Thanks for pointing this out!

                               

                              I am a daily user of CS5.0 - missed that

                               

                              Jarek

                              • 12. Re: Find threaded text frames in document
                                [Jongware] Most Valuable Participant

                                Laubender wrote:

                                 

                                Note: The link "Browse online" below the CS5.5 DOM documentation is showing the CS5 DOM where this method is not available.

                                 

                                Thanks, Uwe -- silly typo on my side. ((Looking around) And you're the first to notice!)

                                 

                                Th.

                                • 13. Re: Find threaded text frames in document
                                  Laubender Adobe Community Professional & MVP

                                  @Jongware – ah.

                                  Since I hardly use the online version of the documentation (just for linking to objects, properties and methods in a forum thread), I came across this only today.

                                  Your chm and html files for InDesign CS5.5 one can download are all fine. :-)

                                   

                                  Wait. Did I check the html files? I hardly use them. I always stick with the chm ones.

                                  (I'm just kidding.) All well now.

                                   

                                  Uwe

                                  • 14. Re: Find threaded text frames in document
                                    suneetha.s Level 1

                                    Hi Jarek,

                                     

                                    Yes exactly !

                                     

                                    I'm in step three, I have to find  previous textframe or object of un-threaded textframe and place anchored object.

                                     

                                    So, In my example screen shot you can find in first page, the previous textframe of an Graphic rectangle is "Learning objectives".

                                     

                                    Awaiting for your response..

                                     

                                    Thanks,

                                    Suneetha

                                    • 15. Re: Find threaded text frames in document
                                      Jump_Over Level 5

                                      Hi,

                                       

                                      I've suggested something different:

                                      • group every unthreated on page
                                      • dont care if threated one is previous or next - just anchor this group anywhere (1st insertionPoint?) inside threated on the same page and set relation to "PAGE EDGE" (copying existing visbleBounds of group)

                                       

                                      Jarek

                                      • 16. Re: Find threaded text frames in document
                                        suneetha.s Level 1

                                        Hi Jarek,

                                         

                                        Thanks for the suggestions.

                                         

                                        Sure, will test with this approach and get back to you with the result.

                                         

                                        Suneetha

                                        • 17. Re: Find threaded text frames in document
                                          suneetha.s Level 1

                                          Hi Jarek,

                                           

                                          I have tested with approach you have suggested. the final outcome I required is to export the document to epub (Flowable). when I anchor the unthreated textframe with Relative to "Page Edge" of any threaded textframes, It will float with the anchored frame only. Even though I have set the X / Y Offsets, in epub it will stick to the textframe which I set anchored points.

                                           

                                          This approach will work fine for PDF. My goal is to create epub file.

                                           

                                          please suggest any other approach for anchoring object to exact position as they present in document.

                                           

                                          Thanks,

                                          Suneetha

                                          • 18. Re: Find threaded text frames in document
                                            Jump_Over Level 5

                                            Hi Suneetha,

                                             

                                            Your outcome determines a solution. Any detail of that.

                                            Script - you are going to create - can find a logic only if you will find that logic first.

                                             

                                            If you are looking for object's order inside your doc - close your eyes and find a rule. Script will do the same way.

                                            If only way to define order is to see it - no way to find a rule.

                                             

                                            Jarek

                                            • 19. Re: Find threaded text frames in document
                                              suneetha.s Level 1

                                              Hi Jarek,


                                              Thanks for findings.


                                              Sorry for not detailing with the logic.


                                              Yes, I have found my logic. Let me explain, and I request your valuable time to read this.


                                              I have InDesign Document with fully formatted. It also contains unthreaded text frames and Graphic rectangle frames (Images) with no anchoring. I have to write tool to do following tasks.


                                              1. Open InDesign document
                                              2. Anchoring unthreaded text frames and Graphic rectangles to the previous or next text frames. ( I’m struck in this step)
                                              3. Applying styles using external style sheet.
                                              4. Then export document to epub v3.0.

                                               

                                              I have logic to do further steps except step 2 of finding previous textframe of unthreaded text frame.

                                               

                                              Please find the below screen shot for better understanding.

                                               

                                              Sample1.png

                                              In above screen shot you find the unthreated Rectangle frame and Textframe.

                                               

                                              Sample2.png

                                              This is how I need to anchor both the objects. So, the previous threaded textframe in first page is learning objectives. I have to find this text frame and set anchor to end insertion point.

                                               

                                              The expected output would be like this.

                                              Sample 3.png

                                              I have tested with two approaches.

                                              1. Page TextFrames

                                               

                                              var doc = app.activeDocument;

                                               

                                              //finding last textframe in the document

                                              var textFrames = doc.pages[0].textFrames;

                                              var lastTextFrame= textFrames[textFrames.length-1];

                                               

                                              //finding unthreated objects in the page

                                              var pageItems = doc.pages[0].pageItems;

                                              for( var i=1; i<pageItems.length; i++)

                                              {

                                                    if(pageItems[i].parentStory.textContainers.length ==1)

                                                    {

                                                         pageItems[i].anchoredObjectSettings.insertAnchoredObject( lastTextFrame.insertionPoints.item(lastTextFrame.contents.length-1), AnchorPosition.ANCHORED)

                                                    }

                                              }

                                               

                                              This approach will not work because when I get page “textframes”, It will not be in the order as the present in page.

                                              Ex:

                                              textFrame[0] =”Chapter1”

                                              textFrame[1] =”Overview”

                                              textFrame[2] =”Learning Objectives”

                                              textFrame[3] =”Figure Caption”

                                               

                                               

                                              But the order I’m getting is

                                              textFrame[0] =”Chapter1”

                                              textFrame[1] =”Figure Caption”

                                              textFrame[2] =” Learning Objectives”

                                              textFrame[3] =” Overview”

                                               

                                              2. PageItems

                                              I have also tested with referring PageItems order. But this would not work because of stacking order of page Items would be last in first placed.

                                               

                                              Hope I have explained my requirement thoroughly.


                                              And expecting your suggestions to complete my task. Its very important !!. please give any other approach to do this.

                                               

                                              Thanks & Regards,

                                              Suneetha

                                              • 20. Re: Find threaded text frames in document
                                                Laubender Adobe Community Professional & MVP

                                                @Suneetha – when you are talking EPUB and EPUB v3.0, do you:

                                                 

                                                1. Talk about Reflowable EPUB (opposed to: Fixed Layout EPUB ? ( I guess so ) )

                                                2. What is the exact InDesign version on what OS platform you want to do the export?

                                                 

                                                It is crucial to know the exact InDesign version!

                                                CS6 was a mess.

                                                CC was quite better.

                                                CC 2014.2 is currently the best in preparing output for Reflowable EPUB or Fixed Layout EPUB as well.

                                                 

                                                Versions before CS6 have all their issues…
                                                That does not mean, that CC 2014.2 has no issues…

                                                 

                                                Uwe

                                                • 21. Re: Find threaded text frames in document
                                                  suneetha.s Level 1

                                                  Hi Laubender,

                                                   

                                                  1. Yes, I do work on Reflowable EPUB.

                                                  2. Windows - InDesign CC 2014  v 10.1

                                                   

                                                  I don't have any issue with exporting ePub v3.0. Please have a look on my previous conversation in which have explained the problem I'm facing.

                                                   

                                                  Thanks,

                                                  Suneetha

                                                  • 22. Re: Find threaded text frames in document
                                                    Laubender Adobe Community Professional & MVP

                                                    Thank you for clarification…
                                                    Um, where exactly is your previous conversation?

                                                     

                                                    Uwe

                                                    • 23. Re: Find threaded text frames in document
                                                      suneetha.s Level 1

                                                      Hi Laubender,

                                                       

                                                      Please find the conversation which i had with 'Jarek'. I have explained the problem where I'm facing.

                                                       

                                                      Hi Jarek,


                                                      Thanks for findings.


                                                      Sorry for not detailing with the logic.


                                                      Yes, I have found my logic. Let me explain, and I request your valuable time to read this.


                                                      I have InDesign Document with fully formatted. It also contains unthreaded text frames and Graphic rectangle frames (Images) with no anchoring. I have to write tool to do following tasks.


                                                      1. Open InDesign document
                                                      2. Anchoring unthreaded text frames and Graphic rectangles to the previous or next text frames. ( I’m struck in this step)
                                                      3. Applying styles using external style sheet.
                                                      4. Then export document to epub v3.0.

                                                       

                                                      I have logic to do further steps except step 2 of finding previous textframe of unthreaded text frame.

                                                      Please find the below screen shot for better understanding.

                                                      ..................................

                                                       

                                                      Thanks

                                                      Suneetha.

                                                      • 24. Re: Find threaded text frames in document
                                                        Jump_Over Level 5

                                                        Hi,

                                                         

                                                        I dont know what specific solution can be found using ID 2014 CC features in UI but a generic way could be to create a function and call it for each page in a doc. The function would:

                                                        • collect all pageItems (array)
                                                        • sort them by geometricBounds[0] value (ascending)
                                                        • iterate through and:
                                                          1.      each time current item is a threated textFrame ==> set its last insertionPoint as a destination
                                                          2. otherwise ==> anchore item in current destination (not sure if original visibleBounds are essential to be copied)


                                                        It assumes the order of pageItems can be based on its top position.


                                                        Jarek

                                                        • 25. Re: Find threaded text frames in document
                                                          Jump_Over Level 5

                                                          Hi,

                                                           

                                                          Take a look on this:

                                                          mPI (app.activeDocument.pages[0])
                                                          function mPI (page) {
                                                            var
                                                            mPItems = page.pageItems.everyItem().getElements(),
                                                            cDest, mAlert,
                                                            cPItem;
                                                            mPItems.sort(geoTopSort);
                                                            while (cPItem = mPItems.shift() ) {
                                                            if (cPItem.hasOwnProperty ("parentStory") && cPItem.parentStory.textContainers.length > 1)
                                                            mAlert = "DEST: " ;
                                                            else
                                                            mAlert = "ANCHOR: " ;
                                                            mAlert +=  cPItem.constructor.name + ": " + cPItem.geometricBounds[0]);
                                                            alert(mAlert);
                                                            }
                                                            }
                                                          function geoTopSort (a,b) {
                                                            return a.geometricBounds[0] >= b.geometricBounds[0];
                                                            }
                                                          
                                                          

                                                           

                                                          Run it for chosen page (for now is set to the page[0] ==> 1st line)

                                                          It can fail in many ways but its just for showing my idea

                                                           

                                                          Jarek

                                                          • 26. Re: Find threaded text frames in document
                                                            suneetha.s Level 1

                                                            Hi Jarek,

                                                             

                                                            Many thanks !!! It's sounds better.

                                                            Let me test with this solution and get back to you with the result.

                                                             

                                                            Suneetha

                                                            • 27. Re: Find threaded text frames in document
                                                              suneetha.s Level 1

                                                              Hi Jarek,

                                                               

                                                              Thank you so much for the solution.

                                                               

                                                              It's works !! :-)

                                                               

                                                              Regards,

                                                              Suneetha