2 Replies Latest reply on Jan 11, 2013 11:46 PM by Peter Kahrel

    Problem creating new document within closure

    Skriptorium

      Hi, I'm struggling to understand why the following doesn't work (InDesign CS5.5, Windows 7). Any clues?

      var dialog = new Window("dialog");
      var button = dialog.add("button", undefined, "Create!");
      button.onClick = function () { app.documents.add(); };
      dialog.show();

      Thanks! George

        • 1. Re: Problem creating new document within closure
          csm_phil Level 4

          Hi Archibald28,

           

          Try the below JS code. I hope you expect this.

           

           

          var win = new Window('dialog');
          var myClickButton = win.add('group');
          myClickButton.alignment = 'right';
          myClickButton.orientation = 'row';
          with(myClickButton){
              var myCancel = myClickButton.add('button', undefined, 'Cancel');
              myCancel.preferredSize = [80,20];
              var myOkButton = myClickButton.add('button', undefined, 'Create', {name:'ok'});
              myOkButton.preferredSize = [80,20];
              }
          var myFlg = 1;
          myCancel.onClick = function () { 
              myFlg = 0;  
              win.close();
              };
          
          win.center();
          win.show();
          
          if(myFlg==0){
              win.close();
              exit(0);
              }
          else{
              app.documents.add();
              }
          

           

           

          thx,

          csm_phil

          • 2. Re: Problem creating new document within closure
            Peter Kahrel Adobe Community Professional & MVP

            George,

             

            Your script doesn't work because dialog-type windows are modal, which means that as long as the window is active you can't do anything in InDesign. You need to use either an approach along the lines of phil's example, or use a palette-type window, which is non-modal:

             

            var dialog = new Window("palette");
            var button = dialog.add("button", undefined, "Create!");
            button.onClick = function () { app.documents.add(); dialog.close()};
            dialog.show();
            

             

            Peter