4 Replies Latest reply on Apr 19, 2010 11:51 PM by andrewbish

    Create a new document from a dialog

    andrewbish

      Our publication has Ads with set width sizes (1 to 7 columns)  35, 73, 110, 148, 186, 224, 262 mm wide.

      the hieght goes from 10mm to 380mm

       

      and i am using a VERY simple script to create them

       

      // Ads size 200x7
      var myDocument = app.documents.add();
      with(myDocument.documentPreferences){
      pageHeight = "200mm";
      pageWidth = "262mm";
      pageOrientation = PageOrientation.landscape;
      pagesPerDocument = 1;
      }

       

      The probelm is i need an indivual script for every size. So 1 script would be better but i am struggling with user dialogs

       

      does anyone know or have an old script that i can look at to get a better understanding of how to write my own.

       

      My final goal is to have a dialog that ask 2 things

       

      Height = user enters any value

      width = 7 predefined choices only (radio buttons)

       

      Using Idesign CS3  PC  javascript

        • 1. Re: Create a new document from a dialog
          Shonkyin Level 3

          Why you want create document through javascript or dialog.

           

          Just go File --> New, and use indesign New Document Windows and enter values that you want.

           

          I have created dialog for your script.

           

          Check below one

           

          var UIresult = myDisplayDialog();
          
          // Ads size 200x7
          var myDocument = app.documents.add();
          with(myDocument.documentPreferences){
          pageHeight = UIresult[1] + "mm";
          pageWidth = UIresult[0] + "mm";
          pageOrientation = PageOrientation.landscape;
          pagesPerDocument = 1;
          }
          
          
          function myDisplayDialog()
             {
                  var myDialog = new Window ('dialog', 'Create New Document');
                  myDialog.alignChildren = "left";
                  var rg0 = myDialog.add ('group');
                  rg0.add('statictext',undefined, 'Select Document Width:');
                  var docuWidth = rg0.add('dropdownList', undefined ,[35, 73, 110, 148, 186, 224, 262]);
                  docuWidth.selection = docuWidth[1];
                  rg0.add('statictext',undefined, 'mm');
                  var rg1 = myDialog.add ('group');
                  rg1.add('statictext',undefined, 'Enter Document Height:');
                  var docuHeight = rg1.add('edittext',undefined, '380');
                  rg1.add('statictext',undefined, 'mm');
                  var rg2 = myDialog.add ('group');
                  rg2.alignment = "right";
                  rg2.add('button', undefined, 'Cancel', {name: 'cancel'});
                  rg2.add('button', undefined, 'OK', {name: 'ok'});
          
          var myResult = myDialog.show();
          if (myResult == 1)
          {
               return [docuWidth.selection.toString (), docuHeight.text];
          }
          if (myResult == 2)
          {
               exit();
          }
          }
          

           

           

          Shonky

          1 person found this helpful
          • 2. Re: Create a new document from a dialog
            andrewbish Level 1

            Thankyou for your direction, i manage to get your script working with a little change(i think there might be a CS4 to CS3 issue).

             

            and yes you are right i could just go file new but most of our work is for a newspaper and ad sizes are give in columns, eg 10 by 7 which translates to 100mm by 263mm, so everytime you create an ad you constantly have to check a chart. so having a script where the columns are already set is a big step forward.

             

            anyway below is the script that works in CS3, i havnt got the radio button working yet, not from a lack of trying, but more from poor scripting references or my lack of being able to understand them.

             

             

             

            var UIresult = myDisplayDialog();

            // Ads size 200x7
            var myDocument = app.documents.add();
            with(myDocument.documentPreferences){
            pageHeight = UIresult[1] + "mm";
            pageWidth = UIresult[0] + "mm";
            pagesPerDocument = 1;
            }
            function myDisplayDialog()
               {
                    var myDialog = new Window ('dialog', 'New Document 7 columns');
                    myDialog.alignChildren = "left";
                    var rg0 = myDialog.add ('group');
                    rg0.add('statictext',undefined, 'name of company');
                        rg0.add('statictext',undefined, 'Select Column Width:');
                 var docuWidth = rg0.add('dropdownlist',undefined,[35, 73, 110, 148, 186, 224, 262]);
              docuWidth.selection = docuWidth[1];
                    rg0.add('statictext',undefined, 'mm');
            var rg1 = myDialog.add ('group');
                    rg1.add('statictext',undefined, 'Enter Document Height:');
                    var docuHeight = rg1.add('edittext',undefined, '380');
                    rg1.add('statictext',undefined, 'mm');
                    var rg2 = myDialog.add ('group');
                    rg2.alignment = "right";
                    rg2.add('button', undefined, 'Cancel', {name: 'cancel'});
                    rg2.add('button', undefined, 'OK', {name: 'ok'});

            var myResult = myDialog.show();
            if (myResult == 1)
            {
                 return [docuWidth.selection.toString (), docuHeight.text];
            }
            if (myResult == 2)
            {
                 exit();
            }
            }

            • 3. Re: Create a new document from a dialog
              Shonkyin Level 3

              Here is your script with Radio Buttons:

               

              var UIresult = myDisplayDialog();
              // Ads size 200x7
              if (UIresult.rb[0]){createDocument("35", UIresult.docHeight);}
              if (UIresult.rb[1]){createDocument("73", UIresult.docHeight);}
              if (UIresult.rb[2]){createDocument("110", UIresult.docHeight);}
              if (UIresult.rb[3]){createDocument("148", UIresult.docHeight);}
              if (UIresult.rb[4]){createDocument("186", UIresult.docHeight);}
              if (UIresult.rb[5]){createDocument("224", UIresult.docHeight);}
              if (UIresult.rb[6]){createDocument("262", UIresult.docHeight);}
              
              function createDocument(docHeight, docWidth)
              {
              var myDocument = app.documents.add();
              with(myDocument.documentPreferences){
              pageHeight = docHeight + "mm";
              pageWidth = docWidth + "mm";
              pagesPerDocument = 1;}
              }
              
              function myDisplayDialog()
                 {
                      var myDialog = new Window ('dialog', 'New Document 7 columns');
                      myDialog.alignChildren = "left";
                      var rg0 = myDialog.add ('group');
                      rg0.add('statictext',undefined, 'Select Column Width:');
                        var rb1 = rg0.add('radiobutton',undefined, '35');
                        var rb2 = rg0.add('radiobutton',undefined, '73');
                        var rb3 = rg0.add('radiobutton',undefined, '110');
                        var rb4 = rg0.add('radiobutton',undefined, '148');
                        var rb5 = rg0.add('radiobutton',undefined, '186');
                        var rb6 = rg0.add('radiobutton',undefined, '224');
                        var rb7 = rg0.add('radiobutton',undefined, '262');
                        rg0.add('statictext',undefined, 'mm');
                        rb1.value = true;
                        var rg1 = myDialog.add ('group');
                      rg1.add('statictext',undefined, 'Enter Document Height:');
                      var docuHeight = rg1.add('edittext',undefined, '380');
                      rg1.add('statictext',undefined, 'mm');
                      var rg2 = myDialog.add ('group');
                      rg2.alignment = "right";
                      rg2.add('button', undefined, 'Cancel', {name: 'cancel'});
                      rg2.add('button', undefined, 'OK', {name: 'ok'});
              var myResult = myDialog.show();
              if (myResult == 1)
              {
                   return {rb : [rb1.value, rb2.value, rb3.value, rb4.value, rb5.value, rb6.value, rb7.value], docHeight : docuHeight.text};
              }
              if (myResult == 2)
              {
                   exit();
              }
              }
              
               
              

               

               

              Shonky

              • 4. Re: Create a new document from a dialog
                andrewbish Level 1

                Wow thanks, i can see where i was going wrong now, i wasnt returning the variables afterwards.

                 

                just one small thing if anyone else is going to use this great script that shonkyin wrote.

                 

                just swap around the height and width in the below line.

                 

                function createDocument(docHeight, docWidth) { var myDocument = app.documents.add();