6 Replies Latest reply on Apr 18, 2013 12:00 AM by Vamitul

    working with Smart Text Reflow

    Vamitul Level 4

      Did anyone managed to trigger /wait for smart text reflow using scripting, in a usefull manner?

       

      here is a bit of my code:

       

         //find docType headers and apply keep
            app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
            app.findTextPreferences.findWhat = "<docType:TaggedRTF>";
            app.changeTextPreferences.startParagraph = StartParagraph.NEXT_ODD_PAGE;
            myStory.changeText();
            //fix tables
            if (myStory.tables.length) {
             /// proceess tables, code too long, not important
      
              }
            }
            // wait for smartReflow
            // how? it seems to be triggered only on idle?
      
            //now check if story overflows    
            if (myStory.overflows) {
              alert('This story has overset text. Please fix before running WordRunner');
            } else {
              // no overflow, proceed with breaking stories
      
      

       

       

      I always get to the alert. Smart reflow only starts after the script has stopped running.

       

      so.. how to wait for smart text reflow?

      i tried using $.sleep .. won't work

      i tried to see if a backgroundTask isn't triggered... it isn't.

      i'm lost, and very much annoyed.

      My only option, for now, is to ask the user to click a button after the text has reflowed. And that sucks!

      please please please someone help!

        • 1. Re: working with Smart Text Reflow
          Vamitul Level 4

          Update. sort of...

           

          Another question .. what is a simple way to make a palette wait for input?

           

           

          var myFlag=true;
          var waitWin=new Window ('palette');
          var doneButton=waitWin.add("button", undefined, "Done");
          doneButton.onClick=function(){
          myFlag=false;
          waitWin.close();
          }
          waitWin.show();
          while(myFlag){$.sleep(10);};
          

           

           

          doesn't seem to work.

          • 2. Re: working with Smart Text Reflow
            TᴀW Adobe Community Professional & MVP

            You have to use #targetengine, and you have to run the script from the

            InDesign scripts panel (not ESTK).

             

            Ariel

            1 person found this helpful
            • 3. Re: working with Smart Text Reflow
              Vamitul Level 4

              Thanks. i know that, and that's what i did.

              Anyway i think i found a workaround for the whole problem:

              The damn smartreflow starts before a preflight check. so i make sure the preflight for the document is turned on, make the modifications i need, than call

              app.activeDocument.activeProcess.waitForProcess();

              works on preliminary test, will get back and report if everything is in order.

              • 4. Re: working with Smart Text Reflow
                Vamitul Level 4

                Well.. it works. It's a ugly cludge, but at least it works. I'm posting a snippet of code, because i'we seen a lot of threads on the same subject, and maby someone else will find it usefull.

                 

                 // save old recompose and set new one
                      var myOldSmartText = app.activeDocument.textPreferences.smartTextReflow;
                      app.activeDocument.textPreferences.smartTextReflow = true;
                      app.activeDocument.textPreferences.addPages = AddPageOptions.END_OF_STORY;
                      app.activeDocument.textPreferences.deleteEmptyPages = true;
                      //find docType headers and apply keep
                      app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
                      app.findTextPreferences.findWhat = "<docType:TaggedRTF>";
                      app.changeTextPreferences.startParagraph = StartParagraph.NEXT_ODD_PAGE;
                      myStory.changeText();
                      //fix tables
                      if (myStory.tables.length) {
                /* long code to process tables, not interesting
                **
                **/
                        
                      }
                     //process style rules
                
                /* long code to preformat text, add/remove space after headings, lists, blocks etc.
                **
                **/
                      // save old preflight options, add new ones
                      var oldPreflight = app.activeDocument.preflightOptions.properties;
                      app.activeDocument.preflightOptions.preflightOff = false;
                
                     // wait a maximum of 40 second for the preflight process. Before it runs, the (not so)Smart  Text Reflow should kick into action.
                      app.activeDocument.activeProcess.waitForProcess(40);
                      //stop preflight for a bit more performance?
                      app.activeDocument.preflightOptions.preflightOff = true;
                      //now check if story overflows? (maby you have a very large cell in a table? some wierd keep options? bad things happen
                
                

                 

                Can i mark my own answer as correct?

                • 5. Re: working with Smart Text Reflow
                  Jump_Over Level 5

                  Hi,

                  Vamitul wrote:

                   

                  Can i mark my own answer as correct?

                  In my opinion you should

                   

                  Did you test omitting waitForProcess() parameter. It should wait for the end regardless how long (short) it takes...

                   

                  rgds

                  Jarek

                  • 6. Re: working with Smart Text Reflow
                    Vamitul Level 4

                    i did.

                    In practice it makes no difference whatsoever if i add the timeout or not, as 40 seconds is usualy about 20 too much for preflight to end.

                    I also don't realy care if the preflight process has ended or not, because it starts only AFTER smart text has finished. So it would probably be smarter to make the timeout value really small (one second)?

                    the reason i added the timeout parameter is for the odd case something 'hangs' and blocks Smart Text Reflow (the most common case for me is a table cell too large to fit in the parent text frame).