6 Replies Latest reply on Apr 20, 2009 7:14 AM by Kasyan Servetsky

    JS CS3 Simple Dialog to change doc starting page.

    John.Kordas Level 1

      This example presents the user a dialog telling them the what their current document starting page is. The user can then change the value and update the starting page number. For some reason I'm getting a error Cannot handle the request because a modal dialog or alert is active. I have set myDialog.close(); before the if statement so should this not stop this error?

       

      I have not added any checks to ensure a doc is open in ID yet.

       

      var myDialog = new Window('dialog', ' Starting Pg No');

       

          myDialog.dPgNo = myDialog.add('panel',undefined,'File details');
          myDialog.dPgNo.alignChildren = 'left';
          myDialog.dPgNo.myPgNo = myDialog.dPgNo.add('group');
          myDialog.dPgNo.myPgNo.group = myDialog.dPgNo.myPgNo.add('group');
          myDialog.dPgNo.btnGroup = myDialog.dPgNo.add('group');
          with (myDialog.dPgNo){
          myPgNo.group.orientation = 'column';
          myPgNo.group.alignChildren = 'right';
          myPgNo.group.preferredSize = [90,15];
          myPgNo.group.st  = myPgNo.group.add('statictext',undefined,'Your Doc starting page is:');
          myPgNo.et = myPgNo.add('edittext', undefined, app.activeDocument.pages[0].name)
          btnGroup.btn = btnGroup.add('button', undefined, 'Update');
          btnGroup.alignment = 'right';
          }

       

      myDialog.dPgNo.btnGroup.btn.onClick = function() {
      myDialog.close();
      var myPagestart = myDialog.dPgNo.myPgNo.et.text;
      if (app.activeDocument.pages[0].name != myPagestart){
      app.activeDocument.pages[0].appliedSection.continueNumbering = false; //<-----------ESTK stops here with the error mentioned before.
      app.activeDocument.pages[0].appliedSection.pageNumberStart = parseInt(myPagestart);
      app.activeDocument.pages[0].appliedSection.sectionPrefix = "";
      alert("Your document start page has been changed to "+myPagestart+".");
      }
      myDialog.show();
      }

       

      myDialog.show();

        • 1. Re: JS CS3 Simple Dialog to change doc starting page.
          Kasyan Servetsky Level 5

          Hi John,


          You don't need to close and reopen the window. Instead of dialog use 'palette' type of the window and run the script in a persistent engine, e.g. #targetengine "session".

           

          Kasyan


          #targetengine "session"
          var myDialog = new Window('palette','Starting Pg No');
              myDialog.dPgNo = myDialog.add('panel',undefined,'File details');
              myDialog.dPgNo.alignChildren = 'left';
              myDialog.dPgNo.myPgNo = myDialog.dPgNo.add('group');
              myDialog.dPgNo.myPgNo.myGroup = myDialog.dPgNo.myPgNo.add('group');
              myDialog.dPgNo.btnGroup = myDialog.dPgNo.add('group');
              with (myDialog.dPgNo){
                  myPgNo.myGroup.orientation = 'column';
                  myPgNo.myGroup.alignChildren = 'right';
                  myPgNo.myGroup.preferredSize = [90,15];
                  myPgNo.myGroup.st  = myPgNo.myGroup.add('statictext',undefined,'Your Doc starting page is:');
                  myPgNo.et = myPgNo.add('edittext', undefined, app.activeDocument.pages[0].name)
                  btnGroup.btn = btnGroup.add('button', undefined, 'Update');
                  btnGroup.alignment = 'right';
              }
          myDialog.show();

           

          myDialog.dPgNo.btnGroup.btn.onClick = function() {
              var myPagestart = myDialog.dPgNo.myPgNo.et.text;
              if (app.activeDocument.pages[0].name != myPagestart){
                  app.activeDocument.pages[0].appliedSection.continueNumbering = false;
                  app.activeDocument.pages[0].appliedSection.pageNumberStart = parseInt(myPagestart);
                  app.activeDocument.pages[0].appliedSection.sectionPrefix = "";
                  alert("Your document start page has been changed to "+myPagestart+".");
              }
          }

          • 2. Re: JS CS3 Simple Dialog to change doc starting page.
            John.Kordas Level 1

            Thanks Kasyan,

             

            For some reason when I tried to run the script from ESTK I kept getting an error could not run session. I ran it form ID and it worked fine. I then went back to ESTK and now it works. Don't know what happened there but it's working now.

             

            Much appreciated.

            • 3. Re: JS CS3 Simple Dialog to change doc starting page.
              Harbs. Level 6

              In scripting, modal dialogs can not make any changes until they are 

              closed. The way I handle these situations when I want modal dialogs is 

              save the settings to a variable, and then after the dialog is closed I 

              make the changes.

               

              Something like this:

              if(myDialog.show()){
                   if(settings){
                   doSomething(settings.setting1);
                   doSomethingElse(settings.setting2);
              }
              

               

              Harbs

              http://www.in-tools.com

              • 4. Re: JS CS3 Simple Dialog to change doc starting page.
                Kasyan Servetsky Level 5
                For some reason when I tried to run the script from ESTK I kept getting an error could not run session.

                 

                Create a persistent engine at start up: e.g. place a scipt containing #targetengine "session" into 'Adobe InDesign CS3\Scripts\Startup Scripts' folder.

                 

                For example:

                 

                #targetengine "session"

                app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

                • 5. Re: JS CS3 Simple Dialog to change doc starting page.
                  John.Kordas Level 1

                  Thanks Harbs,

                   

                  I thought that might have been the case and I tried to pass them to a variable but I must of got it wrong somehow. I may have even try to pass them to a function which is probably why it did not work.

                   

                   

                  Kasyan I think I may have caused the error. I found a post by Harbs a while back where he had a similar line as yours to allow an disallow UserInteractionLevels.

                   

                  The only thing about the palette option is that it does not allow you to run it in ESTK. Over the last few days of getting my head around ScriptUI I found the best time saver was that I could run the dialog in ESTK to see the layout and not have to go back and forth between ID and ESTK. The more I get to know ScriptUI I really do not see myself going back to the classic dialogs.

                  • 6. Re: JS CS3 Simple Dialog to change doc starting page.
                    Kasyan Servetsky Level 5

                    The only thing about the palette option is that it does not allow you to run it in ESTK.

                     

                    It does allow you to do this. But you should run the script in a persistent engine – if you run it in the ‘main’ (not persistent) engine the window will flash open before immediately closing. But so that to be able to run the scriptin it,  you have to create it first: you can do it by start up script, as I showed you in my previous post – the custom engine will be created every time you (re)start InDesign, or by running the script from the scripts panel.

                    As to the UserInteractionLevels string, it is just an example of a start up script – it’s not obligatory in your case.

                     

                    Kasyan