4 Replies Latest reply on Jul 11, 2017 8:36 AM by mikeb41294032

    Help with radio buttons

    mikeb41294032 Level 1

      Hello forum!

       

      Can someone help me make a couple of radio buttons functional for odd or even pages to this existing script?

      I have separate script to create new pages "BEFORE" doc.pages but I would like to have the two options in one.......not two separate scripts.

       

      I tried to reach the person who originally posted the below script but they haven't been on the forum in months.

      Thanks for any help in advance!

       

       

      //original

       

      var doc = app.documents[0]; 

      var masterNames = doc.masterSpreads.everyItem().name; 

      var d = app.dialogs.add({name:"pick a master spread"}); 

      d.dialogColumns.add().staticTexts.add({staticLabel:"Master Pages:"}); 

      var dd = d.dialogColumns.add().dropdowns.add({stringList:masterNames}); 

      if(d.show()){ 

           var index = dd.selectedIndex; 

           d.destroy(); 

      } else { 

           d.destroy();exit(); 

      var master = doc.masterSpreads.item(index); 

      for(var i=doc.pages.length-1;i>=0;i--){ 

           doc.pages.add(LocationOptions.AFTER,doc.pages[i],{appliedMaster:master});

       

      //

       

      var doc = app.documents[0];

      var masterNames = doc.masterSpreads.everyItem().name;

      var d = app.dialogs.add({name:"Apply Master Page"});

      d.dialogColumns.add().staticTexts.add({staticLabel:"Master Pages:"});

      var dd = d.dialogColumns.add().dropdowns.add({stringList:masterNames});

       

       

      //added radio buttons

      var radioBtns = d.dialogColumns.add().radiobuttonGroups.add();

        radioBtns.radiobuttonControls.add({staticLabel:"Odd Pages",checkedState:true});

        radioBtns.radiobuttonControls.add({staticLabel:"Even Pages"});

       

           if(d.show()){

           var index = dd.selectedIndex;

           d.destroy();

           } else {

           d.destroy();exit();

      }

           var master = doc.masterSpreads.item(index);

           for(var i=doc.pages.length-1;i>=0;i--){

           doc.pages.add(LocationOptions.AFTER,doc.pages[i],{appliedMaster:master});

           }

        • 1. Re: Help with radio buttons
          Jump_Over Level 5

          Hi,

           

          Did you consider to modify your masterSpread as predefined two pages  (odd/even)?

           

          Jarek

          • 2. Re: Help with radio buttons
            mikeb41294032 Level 1

            Hi Jarek!

             

            The original script applies the selected master the the even pages or the pages AFTER, so currently running the script on a 10 page document it will give you ten additional pages of the selected master, one AFTER each of the original 10 pages.

             

            Original option is only for the Master pages.

            PM.png

             

            I would like to make the added radio buttons functional, giving the option to add the selected master either before or after the existing pages in a document.

             

            PMO.png

             

            Thanks for any help or guidance you may have!

            M

            • 3. Re: Help with radio buttons
              Jump_Over Level 5

              Hi,

               

              Define a var 'even' to cover selected Button and differ an action:

              var
                  doc = app.activeDocument,
                  masterNames = doc.masterSpreads.everyItem().name,
                  d = app.dialogs.add({name:"Apply Master Page"}),
                  dd, radioBtns, index, even, master;
                 
              d.dialogColumns.add().staticTexts.add({staticLabel:"Master Pages:"});
              dd = d.dialogColumns.add().dropdowns.add({stringList:masterNames, selectedIndex:0});
              radioBtns = d.dialogColumns.add().radiobuttonGroups.add();
              
              radioBtns.radiobuttonControls.add({staticLabel:"Odd Pages",checkedState:true});
              radioBtns.radiobuttonControls.add({staticLabel:"Even Pages"});
              
              if(d.show()){
                  index = dd.selectedIndex;
                  even = radioBtns.selectedButton;
                  d.destroy();
              } else {
                  d.destroy();
                  exit();
              }
              
              master = doc.masterSpreads.item(index);
              
              for(var i=doc.pages.length-1;i>=0;i--){
                  if (even)
                      doc.pages.add(LocationOptions.AFTER,doc.pages[i],{appliedMaster:master});
                  else
                      doc.pages.add(LocationOptions.BEFORE,doc.pages[i],{appliedMaster:master});
                  }
              

               

              Jarek

              • 4. Re: Help with radio buttons
                mikeb41294032 Level 1

                Thanks Jarek!

                 

                I was missing the "even =" and "(even)"  when I was trying to get this to work...........thanks again!