4 Replies Latest reply on Jan 22, 2015 9:05 PM by Teetan VK

    How the ratiobutton call function?

    Teetan VK Level 1

      Hi everyone

       

      I got this script

       

        var d=app.dialogs.add({name:”Define Empty Pages”});

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

        radioBtns.radiobuttonControls.add({staticLabel:”Save”,checkedState:true});

        radioBtns.radiobuttonControls.add({staticLabel:”No Save”});

        radioBtns.radiobuttonControls.add({staticLabel:“Exit”});

        if(!d.show()){d.destroy();}

        var saveOption = radioBtns.selectedButton;

                  d.destroy();

       

                  var docs = app.documents; 

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

                      if (docs[i].saved == false) { 

                          docs[i].save(new File(“~/Desktop/myTestDocument” + (i+1) + “.indd”)); 

                          docs[i].close(); 

                      } 

                      else { 

                          docs[i].close(SaveOptions.NO); 

                      } 

                  }

       

      for close docs without save, but

      I want to remain choice for those unsaved files, so I add open dialog in case for me to decide if I save those unsaved files.

       

      Now, the problem is I don’t know how to let the ratiobutton call function

       

      My aim:

      1) If choose “Save” means save unsaved files, but not others

      2) If choose “No save” means all files no save

      2) If choose “Exit” means unsaved files Exit (remain open) but close others

       

      Thanks

      Regard

       

      Teetan

        • 1. Re: How the ratiobutton call function?
          Chinnadk Level 4

          Try this,

           

          var d=app.dialogs.add({name:"Define Empty Pages"});
          var radioBtns = d.dialogColumns.add().radiobuttonGroups.add();
          var save = radioBtns.radiobuttonControls.add({staticLabel:"Save",checkedState:true});
          var nosave = radioBtns.radiobuttonControls.add({staticLabel:"No Save"});
          var exit = radioBtns.radiobuttonControls.add({staticLabel:"Exit"});
          if(!d.show()){d.destroy();}
          var docs = app.documents;
          switch(radioBtns.selectedButton)
          {
                  case 0:
                      for(var i =0;i<docs.length;i++)
                      {
                              if(docs[i].saved == false)
                              {
                                      docs[i].save(new File(“~/Desktop/myTestDocument” + (i+1) + “.indd”));
                                      docs[i].close();
                                  }
                              else
                              {
                                      docs[i].close(SaveOptions.NO)
                                  }
                          }
                      break;
                  case 1:
                      for(var i =0;i<docs.length;i++)
                          {
                                  docs[i].close(SaveOptions.NO)
                              }
                      break;
                  case 2:
                      exit()
                      break;
              }
          

           

          Regards,

          Chinna

          • 2. Re: How the ratiobutton call function?
            Teetan VK Level 1

            Thank you Chinna

            Thank you very much

             

            but can you help me to fix line 46

            which error in wrong syntax

             

            line 46: "else" not vaild

             

             

            var myDate = new Date; 

            Date.prototype.monthName = function() { 

                var myMonth = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; 

                return myMonth[this.getMonth()]; 

            }//This line was proposed by Marijan Tompa (tomaxxi) 

            var myMonthName = myDate.monthName(); 

            var myYear = myDate.getFullYear(); 

            var myHour = myDate.getHours(); 

            var myMinutes = myDate.getMinutes(); 

             

             

            //open dialog

            var d=app.dialogs.add({name:"Unsaved files Save or not"}); 

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

            var save = radioBtns.radiobuttonControls.add({staticLabel:"Save",checkedState:true}); 

            var nosave = radioBtns.radiobuttonControls.add({staticLabel:"No Save"}); 

            var exit = radioBtns.radiobuttonControls.add({staticLabel:"Exit"}); 

            if(!d.show()){d.destroy();} 

            var docs = app.documents; 

            switch(radioBtns.selectedButton) 

                    case 0: 

                        for(var i = docs.length-1; i >= 0; i--) 

                        { 

                                if(docs[i].saved == false) 

                                { 

                                        docs[i].save(new File("~/Desktop/Doc" + (i+1) + "-" + myDate.getDate() + " " + myMonthName + " " + myYear + " " + myHour + myMinutes + ".indd")); 

                                        docs[i].close(); 

                                    } 

                                else 

                                { 

                                        docs[i].close(SaveOptions.NO) 

                                    } 

                            } 

                        break; 

                    case 1: 

                        for(var i = docs.length-1; i >= 0; i--) 

                            { 

                                    docs[i].close(SaveOptions.NO) 

                                } 

                        break; 

                    case 2: 

                        for(var i =0;i<docs.length;i++) 

                        { 

                                if(docs[i].saved == false)exit(); 

                                    } 

                                else // no vaild

                                { 

                                        docs[i].close(SaveOptions.NO) 

                                } 

                        break; 

                }

             

            thank you so much

            Regard

             

            Teetan

            • 3. Re: Re: How the ratiobutton call function?
              Chinnadk Level 4

              Corrected,

               

              var myDate = new Date; 
              Date.prototype.monthName = function() { 
                  var myMonth = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; 
                  return myMonth[this.getMonth()]; 
              }//This line was proposed by Marijan Tompa (tomaxxi) 
              var myMonthName = myDate.monthName(); 
              var myYear = myDate.getFullYear(); 
              var myHour = myDate.getHours(); 
              var myMinutes = myDate.getMinutes(); 
              
              
              //open dialog
              var d=app.dialogs.add({name:"Unsaved files Save or not"}); 
              var radioBtns = d.dialogColumns.add().radiobuttonGroups.add(); 
              var save = radioBtns.radiobuttonControls.add({staticLabel:"Save",checkedState:true}); 
              var nosave = radioBtns.radiobuttonControls.add({staticLabel:"No Save"}); 
              var _exit = radioBtns.radiobuttonControls.add({staticLabel:"Exit"}); 
              if(!d.show()){d.destroy();} 
              var docs = app.documents; 
              switch(radioBtns.selectedButton) 
              { 
                      case 0: 
                          for(var i = docs.length-1; i >= 0; i--) 
                          { 
                                  if(docs[i].saved == false) 
                                  { 
                                          docs[i].save(new File("~/Desktop/Doc" + (i+1) + "-" + myDate.getDate() + " " + myMonthName + " " + myYear + " " + myHour + myMinutes + ".indd")); 
                                          docs[i].close(); 
                                      } 
                                  else 
                                  { 
                                          docs[i].close(SaveOptions.NO) 
                                      } 
                              } 
                          break; 
                      case 1: 
                          for(var i = docs.length-1; i >= 0; i--) 
                              { 
                                      docs[i].close(SaveOptions.NO) 
                                  } 
                          break; 
                      case 2: 
                          for(var i =0;i<docs.length;i++) 
                          { 
                                  if(docs[i].saved == false)
                                  {
                                          exit(); 
                                      } 
                                  else // no vaild
                                  { 
                                          docs[i].close(SaveOptions.NO) 
                                  } 
                                  break; 
                          }
                  }
              

               

              Regards,

              Chinna

              • 4. Re: How the ratiobutton call function?
                Teetan VK Level 1

                Thank you Chinna

                Thank you so much!

                 

                Teetan