7 Replies Latest reply on Jul 19, 2012 8:47 AM by Rom B

    smartTextReflow & invalid object for this request

    Rom B



      I'm scripting an import of xml files into inDesign. To add pages I use the smartTextReflow feature:


      myDocument.textPreferences.smartTextReflow = true;



      Further on the script I want to get the geometricBounds of some graphics:




      This two steps are working well when I launch the script from ExtendScript Toolkit. But when the script is launched from inDesign, I get this error about geometricBounds: "Invalid object for this request".

      It looks like recompose() does not work from inDesign, while it does from ExtendScript Toolkit... I'm kind of struggling with this problem for some hours now.


      Let me know if you need more informations and thanks for your help :-)

        • 1. Re: smartTextReflow & invalid object for this request
          absqua Level 4

          recompose() should work the same whether the script is called from InDesign or the ESTK. Maybe you should post a minimal but complete script that demonstrates the problem. Also tell us what version you're using.



          • 2. Re: smartTextReflow & invalid object for this request
            Rom B Level 1

            Thanks for your help. I've been long to answer because I've made some more testings.


            So I'm using a desktop version of inDesign CS4. First, here is a small part of my import function, wich works when called from ESTK. Then I'll try to explain the problems when called from inDesign. It's exactly the same code exept for some paths.


            // 1. import XML and move XML content into the inDesign template


            __processRuleSet(myDocument.xmlElements.item(0), [(new displayXML)]);

            // 2. Resize graphics at 10% to avoid them being bigger than a text frame, thus creating pages endlessly at the next step

            images = myStory.allGraphics;

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

                 images[i].parent.horizontalScale = 10;

                 images[i].parent.verticalScale = 10;


            // 3. Smart text reflow

            myDocument.textPreferences.smartTextReflow = true;

            myDocument.textPreferences.addPages = AddPageOptions.END_OF_STORY;

            myDocument.textPreferences.limitToMasterTextFrames = true;

            myDocument.textPreferences.preserveFacingPageSpreads = true;

            myDocument.textPreferences.deleteEmptyPages = true;


            // 4. Resize the graphics at the size of a text frame. To do so I first take the bounds of the rectangle in wich they are included.

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

                 var hRectangle = image[i].parent.geometricBounds[2] - graphic.parent.geometricBounds[0];

                 // etc.



            Now this doesn't work at well from inDesign. First, smartTextReflow has no effect, I guess it's because the recompose() method doesn't work. Maybe recompose doesn't exist on the desktop version of inDesign, as said here:



            Actually, to make it trickier, it's a little bit more random if smartTextReflow works or not. It can depend of other parts of the script, where I link some paragraphs together, making inDesign recomposing the text without the recompose method.

            To make it even more trickier, sometimes smartTextReflow works even when there is nothing to force inDesign to recompose the document...


            So instead of using recompose() I've written a forceRecompose() function which adds a space at the end of the first paragraph of the document, to force inDesign to recompose and to make smartTextReflow works in any cases.

            I can put the code here but it's still a bit rough.


            Now I still have the problem of getting the geometricBounds of the graphics, with this message : "Invalid object for this request".

            My hypothesis is it's because smartTextReflow starts adding pages when the script stops running. So when the script tries to get the bounds of the graphics, they aren't yet placed on a page so it can't get it.

            But when the script is called from ESTK, smartTextReflow and recompose() would make inDesign add the pages while the script is still running, making it possible for the graphics to be resized.


            Sorry for these long explanations, I've tried to make it clear.

            Anyway, every help to understand better the behavior of inDesign would be appreciated.

            • 3. Re: smartTextReflow & invalid object for this request
              Rom B Level 1

              To make the explanations even shorter :


              1) recompose works when the script is called from ETSK, but it doesn't when it's called from inDesign. This may be because recompose doesn't exist on the desktop version of inDesign?


              2) smartTextReflow doesn't have the same behavior depending on where the script is called from. If called from ETSK, it adds pages while the script is still running. If called from inDesign, it adds pages after the script stops running.

              • 4. Re: smartTextReflow & invalid object for this request
                absqua Level 4

                Thank you for providing more information, but I'm afraid I still don't know what to tell you.


                A few thoughts:

                1. I don't have a lot of experience with smart text reflow in a scripted setting, but I have used it and haven't seen the race condition-type problem it seems like you're seeing.

                2. The specific error ("Invalid object for this request") you're seeing when trying to access an inline rectangle's geometricBounds is because the rectangle is in the overset portion of the story. I think you already know this.

                3. recompose() definitely exists in the desktop version—or you would get an error calling it. I normally call it on a story rather than entire document though. You should probably call it at the end of each iteration of your inline rectangle resizing loop if you're seeing these problems.

                • 5. Re: smartTextReflow & invalid object for this request
                  Rom B Level 1

                  Ok, thanks for your help. Here is what I did:


                  - recompose() doesn't work better if called on a story rather than document, but it was easy to fix it with a forceRecompose() function, even if the solution is less neat.


                  - smartTextReflow still seems to run asyncronous, so most of the time it starts add pages when the script has finished executing or too late. Even with some $.sleep(10000) it's still unusable this way. I got around the problem by moving in a second script all the functions which needded to be executed after all pages were added. So now the user has to call two scripts successively, until I find a better solution.


                  I'm still a bit upset against ESTK which doesn't behave like inDesign, forcing me to recode what should have worked on both.

                  • 6. Re: smartTextReflow & invalid object for this request
                    absqua Level 4

                    Did you try putting a recompose() in each iteration of your resizing loop?

                    • 7. Re: smartTextReflow & invalid object for this request
                      Rom B Level 1

                      I did, with no effect (smartTextReflow didn't add one page even after the end of the script).


                      I also tried with my forceRecompose() function on the loop. It worked a little bit better: smartTextReflow added the pages after the script finished executing, so too late for the resize function. So I moved forceRecompose() out of the loop as it needs to be called only once.