7 Replies Latest reply on May 13, 2014 10:16 PM by hasvi

    Correct my script

    hasvi Level 1

      Hi

       

      Its running but 'Advanced Type default setting' value is not updated in my Indesign file. Pls correct my script.

      var w = new Window ("dialog", "Template Checklist", undefined, {closeButton: false});
      w.alignChildren = "left";
      var check1  = w.add ("checkbox", undefined, "Preference settings");
      
      
         if (check1.value == true)
       {
          //this is 'Advanced Type' default setting
          myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.inches;
          myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.inches;
          myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
          myDocument.textPreferences.superscriptPosition=33;
          myDocument.textPreferences.superscriptSize=70;
          myDocument.textPreferences.subscriptPosition=33;
          myDocument.textPreferences.subscriptSize=70;
          myDocument.textPreferences.smallCap=75;
          app.imePreferences.inlineInput=true;
          }
      var buttons = w.add ("group");
      buttons.add ("button", undefined, "Ok");
      buttons.add ("button", undefined, "Cancel");
      w.show ();
      var ProgressBar = function(/*str*/title)
      {
           var w = new Window('palette', ' '+title, {x:0, y:0, width:340, height:60}),
                pb = w.add('progressbar', {x:20, y:12, width:300, height:12}, 0, 100),
                st = w.add('statictext', {x:10, y:36, width:320, height:20}, '');
           st.justify = 'center';
           w.center();
           this.reset = function(msg,maxValue)
                {
                st.text = msg;
                pb.value = 0;
                pb.maxvalue = maxValue||0;
                pb.visible = !!maxValue;
                w.show();
                };
           this.hit = function() {++pb.value;};
           this.hide = function() {w.hide();};
           this.close = function() {w.close();};
      };
      //------------------------------------------------
      //      SAMPLE CODE
      //------------------------------------------------
      function main()
      {
           var pBar = new ProgressBar("Running");
           var i;
           
           // Routine #1
           pBar.reset("Please wait Processing ...", 100);
           for( i=0 ; i < 100; ++i, pBar.hit() )
                {
                $.sleep(10);
                }
           // Routine #2 
           pBar.close();
           }
      main();
      exit();
      

       

      Pls correct my script

       

      by

      hasvi

        • 1. Re: Correct my script
          Chinnadk Level 4

          Hi Hasvi,

           

          Corrected code.

           

          var w = new Window ("dialog", "Template Checklist", undefined, {closeButton: false}); 

          w.alignChildren = "left"; 

          var check1  = w.add ("checkbox", undefined, "Preference settings"); 

             

          var buttons = w.add ("group"); 

          buttons.add ("button", undefined, "Ok"); 

          buttons.add ("button", undefined, "Cancel"); 

          w.show (); 

          var myDocument = app.activeDocument;

          if (check1.value == true) 

              //this is 'Advanced Type' default setting 

              myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.inches; 

              myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.inches; 

              myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin; 

              myDocument.textPreferences.superscriptPosition=33; 

              myDocument.textPreferences.superscriptSize=70; 

              myDocument.textPreferences.subscriptPosition=33; 

              myDocument.textPreferences.subscriptSize=70; 

              myDocument.textPreferences.smallCap=75; 

              app.imePreferences.inlineInput=true; 

              }

          var ProgressBar = function(/*str*/title) 

               var w = new Window('palette', ' '+title, {x:0, y:0, width:340, height:60}), 

                    pb = w.add('progressbar', {x:20, y:12, width:300, height:12}, 0, 100), 

                    st = w.add('statictext', {x:10, y:36, width:320, height:20}, ''); 

               st.justify = 'center'; 

               w.center(); 

               this.reset = function(msg,maxValue) 

                    { 

                    st.text = msg; 

                    pb.value = 0; 

                    pb.maxvalue = maxValue||0; 

                    pb.visible = !!maxValue; 

                    w.show(); 

                    }; 

               this.hit = function() {++pb.value;}; 

               this.hide = function() {w.hide();}; 

               this.close = function() {w.close();}; 

          }; 

          //------------------------------------------------ 

          //      SAMPLE CODE 

          //------------------------------------------------ 

          function main() 

               var pBar = new ProgressBar("Running"); 

               var i; 

                

               // Routine #1 

               pBar.reset("Please wait Processing ...", 100); 

               for( i=0 ; i < 100; ++i, pBar.hit() ) 

                    { 

                    $.sleep(10); 

                    } 

               // Routine #2  

               pBar.close(); 

               } 

          main(); 

          exit();

          • 2. Re: Correct my script
            hasvi Level 1

            Hi Chinna,

             

            thanks again

             

            by

            Hasvi

            • 3. Re: Correct my script
              hasvi Level 1

              Hi Chinna,

               

              If I select the ok button the 'processing completed' dialog is running, if I give cancel that time also its running. How to stop this 'processing completed' dialog running script for 'Cancel' button.

               

               

              by

              hasvi

              • 4. Re: Correct my script
                Chinnadk Level 4

                Hi Hasvi,

                 

                buttons.add ("button", undefined, "Cancel");


                Replace the above line(6th line of your script) with below,

                 

                var Exit = 0;

                var cancel = buttons.add ("button", undefined, "Cancel")

                        cancel.onClick = function()

                        {

                                w.close();

                                Exit = 1;

                            }

                w.show ();

                if(Exit ==1)

                {

                        this.exit();

                    }

                 

                Regards,

                Chinna

                • 5. Re: Correct my script
                  hasvi Level 1

                  Hi Chinna,

                   

                  This is script is perfect for click on 'Cancel', but if I click on 'Ok' button, one big dialog box opened I press Esc key after that only 'processing completed' running. Pls help  for this issue.

                   

                  by

                  hasvi

                  • 6. Re: Correct my script
                    Chinnadk Level 4

                    Hi Hasvi,

                     

                    Try this,

                     

                    var w = new Window ("dialog", "Template Checklist", undefined, {closeButton: false});

                    w.alignChildren = "left";

                    var check1  = w.add ("checkbox", undefined, "Preference settings");

                     

                     

                    var buttons = w.add ("group");

                    buttons.add ("button", undefined, "Ok");

                     

                     

                    var Exit = 0;

                    var cancel = buttons.add ("button", undefined, "Cancel")

                            cancel.onClick = function()

                            {

                                    w.close();

                                    Exit = 1;

                                }

                    w.show ();

                    if(Exit ==1)

                    {

                            this.exit();

                        }

                     

                     

                     

                     

                    var myDocument = app.activeDocument;

                    if (check1.value == true)

                    {

                        //this is 'Advanced Type' default setting

                        myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.inches;

                        myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.inches;

                        myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

                        myDocument.textPreferences.superscriptPosition=33;

                        myDocument.textPreferences.superscriptSize=70;

                        myDocument.textPreferences.subscriptPosition=33;

                        myDocument.textPreferences.subscriptSize=70;

                        myDocument.textPreferences.smallCap=75;

                        app.imePreferences.inlineInput=true;

                        }

                    var ProgressBar = function(/*str*/title)

                    {

                         var w = new Window('palette', ' '+title, {x:0, y:0, width:340, height:60}),

                              pb = w.add('progressbar', {x:20, y:12, width:300, height:12}, 0, 100),

                              st = w.add('statictext', {x:10, y:36, width:320, height:20}, '');

                         st.justify = 'center';

                         w.center();

                         this.reset = function(msg,maxValue)

                              {

                              st.text = msg;

                              pb.value = 0;

                              pb.maxvalue = maxValue||0;

                              pb.visible = !!maxValue;

                              w.show();

                              };

                         this.hit = function() {++pb.value;};

                         this.hide = function() {w.hide();};

                         this.close = function() {w.close();};

                    };

                    //------------------------------------------------

                    //      SAMPLE CODE

                    //------------------------------------------------

                    function main()

                    {

                         var pBar = new ProgressBar("Running");

                         var i;

                         

                         // Routine #1

                         pBar.reset("Please wait Processing ...", 100);

                         for( i=0 ; i < 100; ++i, pBar.hit() )

                              {

                              $.sleep(10);

                              }

                         // Routine #2 

                         pBar.close();

                         }

                    main();

                    exit();

                     

                    Regards,

                    Chinna

                    • 7. Re: Correct my script
                      hasvi Level 1

                      Hi chinna,

                       

                      Excellent thanks again

                       

                      by

                      hasvi