7 Replies Latest reply on Feb 15, 2013 10:56 PM by Peter Kahrel

    How could I listen for a modal dialog?

    KuddRoww Level 1

      I'm opening a bunch of files and every 500 or so I have a Modal dialog that pops up. Some of these files are 10 years old so the fonts are retired etc. Is there a way to detect if a modal dialog pops up when a file is opened? If so is there also a way to delay the next loop iteration until the dialog has been dealt with but still have the userInteractionLevel set to never?

        • 1. Re: How could I listen for a modal dialog?
          Peter Kahrel Adobe Community Professional & MVP

          You can disable errors with the following statement:

           

          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
          

           

          which suppresses most (if not all) dialogs. Therefore you musn't forget to enable interaction when you're done:

           

          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
          

           

          Peter

          • 2. Re: How could I listen for a modal dialog?
            KuddRoww Level 1

            Unfortunately it supresses most, not all, dialogs. When the loop continues to iterate without the dialog having been resolved the application crashes. Obviously I can't ascertain if this is exactly why it crashes, the crash reports don't appear to be particularly explicit.

             

            Hence if I could at least divert the the loop when a particular modal appeared, say missing font, then I'd be able to handle it on its extremely exceptional basis.

             

            Even something like:

            app.open(File(file));

            if(app.modal){File.close(SaveOptions.NO)};

             

            Thanks for the suggestion Peter, much appreciated.

            • 3. Re: How could I listen for a modal dialog?
              Peter Kahrel Adobe Community Professional & MVP

              It would be interesting to know which dialog still pops up. Missing links and missing fonts are suppressed, that I know for certain. Don't know what else could be wrong during file open. Trying to open a newer version file maybe, e.g. trying to open a CS6 file in CS5?

               

              Peter

              • 4. Re: How could I listen for a modal dialog?
                KuddRoww Level 1

                You're right. I just assumed that because the files I opened had outdate fonts that had to be the cause. It's not.

                 

                So my next question becomes if interacting with objects within an object causes the application (InDesign) to unexpectedly crash, how can you tell why?

                • 5. Re: How could I listen for a modal dialog?
                  Peter Kahrel Adobe Community Professional & MVP

                  What exactly do you mean when you say "interacting with objects within an object"?

                  • 6. Re: How could I listen for a modal dialog?
                    KuddRoww Level 1

                    for(var i = 0; i<app.activeDocument.allPageItems.length; i++){
                        var pageItem = app.activeDocument.allPageItems[i];
                        switch(pageItem.constructor.name)
                        {
                            case "TextFrame":
                            var tf = pageItem;
                            handleTextFrame(tf);
                            }
                        }

                    function handleTextFrame(textFrame){
                        //Handle paragraphs first, then images and finally handle the Objective Headers
                        for(var i = 0; i<textFrame.paragraphs.length; i++){
                          //  alert(textFrame.paragraphs.length);
                            if(textFrame.paragraphs[i].length>2){
                    //try and create paragraph outline, empty paragraphs return NoPathCreated, escape with continue
                                try{var outlines = textFrame.paragraphs[i].createOutlines(false)}catch(e){
                                    continue
                                }
                    var GB = outlines[0].geometricBounds;
                    outlines[0].remove();
                            }
                        }
                        var textFramePageItems = textFrame.allPageItems;
                               
                        }

                    Sorry I should have typed objects within a document...

                     

                    Here's an example:

                     

                    I'm getting the geometricBounds here so that I can "liberate" a series of paragraphs from their parent textFrame. I want to basically create a file which has text that is exclusively linked, as opposed to the contents actually being contained within the textFrame.

                     

                    Now when I run this I assume that it will have a relatively benign effect on the original document, I am creating an outline without deleting the original, and then I'm deleting the outlines once I capture their bounds.

                     

                    When I run the script at first it appears that everything has executed correctly. Then If I scroll up on the document, not down -  I can scroll down fine, the application crashes.

                     

                    Now this only seems to occur on certain documents because I've successfully implemented it on other documents. It only <i>seems</i> to occur sporadically. If some document objects have a crash behaviour when the script is implemented upon them and others don't I'd like to know why.  I realize this question of knowing why in an ambiguous sort of way isn't fair, I just feel that if an application is going to crash it should be fairly explcit as to why its crashing if the interactions are trivial.

                     

                    I hope that makes sense.

                     

                    Thanks Peter

                    • 7. Re: How could I listen for a modal dialog?
                      Peter Kahrel Adobe Community Professional & MVP

                      I'm afraid it doesn't make much sense to me. What do you mean when you say '"liberate" a series of paragraphs from their parent text frame'? And what is 'text that is exclusively linked, as opposed to the contents actually being contained within the text frame'?

                       

                      The behaviour you describe I've seen too: a document in which you could scroll down but not up. Happened just with one document, it was quite a while ago, no idea what was wrong. In your case, since you say that you have a few documents that crash, can you see any common characteristics of those documents? Any features that those documents have and the well-behaved documents don't?

                       

                      Another word for crash is 'unexpected behaviour', which is why they don't announce themselves:) InDesign writes crash reports somewhere (but I don't know where they're placed), maybe they can shed some light on the reason why the crashes occur.

                       

                      Finally, your first bit of code puts a lot of strain on your script. It has nothing to do with your problem, most likely. You create much unneeded overhead in the first two lines: if a document contains 500 page items, then the script builds an array of those page items 1,000 times. Do it just once. And the switch is unnecessary because you test for just one condition. So this is more efficient:

                       

                      var pItems = app.activeDocument.allPageItems;
                      for(var i = 0; i<pItems.length; i++){
                          if (pItems[i].constructor.name == 'TextFrame'){
                              handleTextFrame(pItems[i]);
                          }
                      }
                      

                       

                      In your handleTextFrame function, the line 'var GB = . . .' doesn't appear to do anything useful (you don't use GB), and the last line in the function doesn't do anything either, so if you remove those two lines, the script becomes simpler. Or did you leave code out in your example?

                       

                      Peter