10 Replies Latest reply on Apr 23, 2011 10:26 AM by tpk1982

    Need your help experts....

    tpk1982 Level 4

      Hi,

       

      Untitled.jpg

       

      The above screeshot shows a spread. In page 2(Recto) top, there is a line alone standing from the paragraph of page 1(arrow mark in attachment). I need a script to identify this kind of instances in whole document. Is it possible find and alert the pages have this kind of orphans by Javascript. It does ignore a single line paragraph if comes in the document.

       

      I take the no. of lines from page1 and can compare with page 2, if any lines come from page 1, then count the lines, if it will more than 1, then alert orphan. Maybe this is what i think about this issue for scripting.

       

      I expect a solution for this issue from you.

       

      Advance thanks

       

       

        • 1. Re: Need your help experts....
          tpk1982 Level 4

          Is there any updates? I am waiting here to know whether it is possible or not?

          • 2. Re: Need your help experts....
            Mayhem SWE Level 2

            You expect a solution? Certainly possible. The basic algorithm was easy, the hard part was figuring out how to reveal the found result in the viewport. Currently it only looks for orphans across linked text frames but could be extended to support text columns as well using the same logic.

             

            (function () {
                 for (var story = 0; story < app.activeDocument.stories.length; story++) {
                      var currentStory = app.activeDocument.stories[story];
                      for (var frame = 0; frame< currentStory.textContainers.length; frame++) {
                           var currentParagraph = currentStory.textContainers[frame].paragraphs[0];
                           if (currentParagraph.parentTextFrames.length > 1 && currentParagraph.lines[-1] == currentParagraph.parentTextFrames.pop().lines[0]) {
                                currentParagraph.lines[-1].select(SelectionOptions.REPLACE_WITH);
                                return revealSelection();
                           }
                      }
                 }
                 alert("No orphans found.");
            }())
            
            function revealSelection () {
                 if (Boolean(app.documents.length) && Boolean(app.selection.length)) {
                      var selectionParent = app.selection[0].hasOwnProperty('parentPage') ? app.selection[0].parentPage : getParentPage(app.selection[0]);
                      try {
                           if (selectionParent.constructor == Page.prototype.constructor) {
                                app.activeDocument.layoutWindows.everyItem().activePage = selectionParent;
                                app.activeDocument.layoutWindows.everyItem().zoom(ZoomOptions.FIT_SPREAD);
                                return true;
                           } else if (selectionParent.constructor == Spread.prototype.constructor) {
                                app.activeDocument.layoutWindows.everyItem().activeSpread = selectionParent;
                                app.activeDocument.layoutWindows.everyItem().zoom(ZoomOptions.SHOW_PASTEBOARD);
                                return true;
                           } else
                                return false;
                      } catch (error) {
                           return false;
                      }
                 } else
                      return false;
            }
            
            function getParentPage (target) {
                 return target.constructor == Application.prototype.constructor ? null : (target.constructor == Page.prototype.constructor || target.constructor == Spread.prototype.constructor ? target : getParentPage(target.hasOwnProperty('parentTextFrames') ? target.parentTextFrames[0] : target.parent));
            }
            

             

            Do use more descriptive topic names in the future.

            1 person found this helpful
            • 3. Re: Need your help experts....
              Reese 0o0o Level 1

              Looks like someone has a scripting 'solution' for you. I'm wondering why you would need a script for that at all.

               

              If the final objective is to eliminate orphened lines, then using 'keep options' in your paragraph styles should eliminate the need.

              • 4. Re: Need your help experts....
                tpk1982 Level 4

                Hi,

                 

                Thank you so much for giving this script. It is really useful. But unfortunately it will not fulfill my requirement. The script will need to find throughout the entire document. Current script only looking for selective text frame. Is it possible to look entire document by script and alert what are the pages contain orphan.

                 

                P.S. Some of my clients don't want keepoptions. So I am not tried that.

                 

                Thanks

                • 5. Re: Need your help experts....
                  Mayhem SWE Level 2

                  You already have the algorithm for finding the orphans. Modifying the script to provide the results as a list isn't difficult!

                   

                  #target indesign
                  #targetengine Orphans
                  var orphans = new Array();
                  for (var story = 0; story < app.activeDocument.stories.length; story++) {
                       var currentStory = app.activeDocument.stories[story];
                       for (var frame = 1; frame< currentStory.textContainers.length; frame++) {
                            var currentParagraph = currentStory.textContainers[frame].paragraphs[0];
                            if (currentParagraph.parentTextFrames.length > 1 && currentParagraph.lines[-1] == currentParagraph.parentTextFrames.pop().lines[0]) {
                                 orphans.push(getParentPage(currentParagraph.lines[-1]) + ": " + currentParagraph.lines[-1].contents.slice(0, -1));
                            }
                       }
                  }
                  var result = new Window('palette', "Orphans", undefined, {resizeable: true});
                  result.onResize = function (event) {this.layout.resize();}, result.alignChildren = ['fill', 'fill'], result.add('edittext', undefined, orphans.join('\n'), {multiline: true}), result.show();
                  
                  function getParentPage (target) {
                       return target.constructor == Application.prototype.constructor ? "?" : (target.constructor == Page.prototype.constructor || target.constructor == Spread.prototype.constructor ? target.name : getParentPage(target.hasOwnProperty('parentTextFrames') ? target.parentTextFrames[0] : target.parent));
                  }
                  

                   

                  If things are quiet at work next week I might spend some time fleshing this out a bit more. A palette with an automatically updating listbox which lets you locate and view all orphans in a document might actually be a useful tool even for other designers at my agency.

                  • 6. Re: Need your help experts....
                    tpk1982 Level 4

                    Hi Mayhem,

                     

                    Thanks for you, spending valuable time for this issue. I ran the script. But it will show the below error message.

                    orphan.JPG

                     

                    May i know what is the real problem, i want to add your previous script code with new one?

                    • 7. Re: Need your help experts....
                      Mayhem SWE Level 2

                      Hmm, works fine for me. Either your document contains something which I did not take into account, or it is related to changes made between CS5 (which you seem to be running) and CS3 (which I am still on) which would be difficult for me to troubleshoot. Ohh and the new code replaces the old code entirely, don't put both old and new versions in the same file.

                      • 8. Re: Need your help experts....
                        tpk1982 Level 4

                        Hi Mayhem,

                         

                        It's working fine. There are two limitations with this script i.e.

                         

                        1) If you have empty frames, the screenshot what i sent earlier will appear. So you don't have any empty frames.

                         

                        2) If you don't have orphan in your document, though the window will open with none. So it will not give any alert message.

                         

                         

                        Anyhow it is great work, Thanks....Thanks....Thanks....Thanks....Thanks....Thanks....Thanks....Thanks....Thanks... .Thanks.....

                        • 9. Re: Need your help experts....
                          tpk1982 Level 4

                          Hi Mayhem,

                           

                          I tried to eliminate the two issues below, but i failed. Can you please do it for me?

                           

                           

                          1) If you have empty frames, the screenshot what i sent earlier will appear. So you don't have any empty frames.

                           

                          2) If you don't have orphan in your document, though the window will open with none. So it will not give any alert message.

                          • 10. Re: Need your help experts....
                            tpk1982 Level 4

                            Hi,

                             

                            Anyone help regarding this?