7 Replies Latest reply on Mar 25, 2015 8:02 AM by nicolaik

    app.open not responding if called from inside onclick()

    AL3XIO

      !

      Hi all.

      Working on a script for InDesign CC 2014 I found this problem : if I call app.open() from inside button.onclick() it stops and nothing happens. Since I'm a beginner with Javascript I'm probably doing something wrong, but I can not figure out where I'm wrong. If executed without onclick it works....

      There is another method to achieve the same result?

      As my project is still under construction, I place only the portion of code relating to the problem.

      I hope someone can help me, I can not get out of this hitch.

      Thanks in advance.

       

      var book_info;
      var w1 = new Window ("dialog", "TEST");
          w1.minimumSize.height = 50;
          w1.minimumSize.width = 50;
           var p1 = w1.add ("panel");
              sel_button = p1.add ("button", undefined, "Open a book");
           var g1 = w1.add ("group");
              g1.add("button", undefined, "Cancel");
              g1.add("button", undefined, "OK");
      
      sel_button.onClick = function(){
          var theFile = File.openDialog ("Select the book file to open...");
          get_data(theFile);
              alert(book_info.filePath + "\r" + book_info.name);
          book_info.close();
      };
      
      w1.show();
      
      function get_data(data) {
          app.open(data);
          book_info = app.activeBook;
              alert("INSIDE FUNCTION" + book_info.filePath + "\r" + book_info.name);
          return data;
      }
      
        • 1. Re: app.open not responding if called from inside onclick()
          Loic.Aigon Adobe Community Professional

          Hi

           

          Since you are using a modal dialog, it's likely that InDesign can't open a document nor do anything until you close the dialog. Your solution is either to close the dialog prior to open the document or to use a non modal dialog (i.e. "palette").

           

          HTH,

           

          Loic

          http://www.ozalto.com

          • 2. Re: app.open not responding if called from inside onclick()
            nicolaik Level 1

            I tried to run the sample code and add w1.close(); at line 13. This still gives me  a modal dialogue error. I saw a few threads here and stackoverflow discussing the problem with no solution. I had the same problem before and resolved it (in a way) by taking logic away from onClick event.

            My version is 5.5 on a MAC

            Changing to "palette" must be the way forward, I will definitely investigate it tomorrow. Loic.Aigon,thanks for an idea

            • 3. Re: app.open not responding if called from inside onclick()
              Loic.Aigon Adobe Community Professional

              hello,

              try this :

              var book_info;  
              var theFile;
              var w1 = new Window ("dialog", "TEST");  
                  w1.minimumSize.height = 50;  
                  w1.minimumSize.width = 50;  
                   var p1 = w1.add ("panel");  
                      sel_button = p1.add ("button", undefined, "Open a book");  
                   var g1 = w1.add ("group");  
                      g1.add("button", undefined, "Cancel");  
                      g1.add("button", undefined, "OK");  
                
              sel_button.onClick = function(){  
                  theFile = File.openDialog ("Select the book file to open...");  
              
              
                if ( !theFile ) return;
              
              
                w1.close(1);
              };  
                
              if ( w1.show() == 1 ) {
                if ( theFile ) {
                get_data(theFile);  
                alert(book_info.filePath + "\r" + book_info.name);  
                book_info.close();  
                }
              }
                
              function get_data(data) {  
                  app.open(data);  
                  book_info = app.activeBook;  
                      alert("INSIDE FUNCTION" + book_info.filePath + "\r" + book_info.name);  
                  return data;  
              }
              

               

              Loic

              http://www.ozalto.com

              • 4. Re: app.open not responding if called from inside onclick()
                nicolaik Level 1

                Thanks,Loic.Aigon

                 

                A better solution than mine. I just used a variable set inside the select button and check for the value after the window close. You can use different variables for different buttons. The approach is quite  similar. Reusing Loic.Aigon code:

                 

                var book_info;   
                var theFile; 
                var getData;
                var w1 = new Window ("dialog", "TEST");   
                    w1.minimumSize.height = 50;   
                    w1.minimumSize.width = 50;   
                    var p1 = w1.add ("panel");   
                        sel_button = p1.add ("button", undefined, "Open a book");   
                    var g1 = w1.add ("group");   
                        g1.add("button", undefined, "Cancel");   
                        g1.add("button", undefined, "OK");   
                   
                sel_button.onClick = function(){   
                    theFile = File.openDialog ("Select the book file to open...");  
                  getData =1;         
                  w1.close(1); 
                };   
                   
                w1.show()
                
                if (  getData ==1) { 
                  if ( theFile ) { 
                  get_data(theFile);   
                  } 
                } 
                   
                function get_data(data) {   
                    app.open(data);   
                    book_info = app.activeBook;   
                        alert("INSIDE FUNCTION" + book_info.filePath + "\r" + book_info.name);   
                    return data;   
                } 
                
                • 5. Re: app.open not responding if called from inside onclick()
                  AL3XIO Level 1

                  Hi Loc.Aigon and nicolaik.

                  Thanks a lot for your suggestions, now I have to check which one fits better to my project.

                  I hope to check before tonight, now I have to deal with other problems .

                  I update you as soon as possible. Thanks again.

                   

                  (Palette is very interesting....)

                  • 6. Re: app.open not responding if called from inside onclick()
                    AL3XIO Level 1

                    I was able to test your suggestions.

                    In my project I need to display results from previous entries. I tried using the proposed script, but there is the problem of the reopening of the dialog window after getting the data. I tried to make some attempt unsuccessful, and sincerely I think there is no solution to this.

                    Therefore in my case the best solution is to change from "dialog" to "palette".

                    Many thanks to you both for the help.

                     

                    I do not want to hurt anyone, but I check the correct answer to Loic.Aigon for suggesting the "palette".

                    • 7. Re: app.open not responding if called from inside onclick()
                      nicolaik Level 1

                      No problem, Loic.Aigon posted a working sample first anyway. From what you describe, it looks like you should be using palette in any case. Good luck!.