10 Replies Latest reply on Nov 10, 2012 1:58 AM by pixxxel schubser

    Uncaught exception when I update window

    Harsh V Sharma Level 1

      Hi All,

       

      I want to show a progress bar while executing script.

      and i am using the following code for that:

       

      var win = new Window("palette", "SnpCreateProgressBar", [150, 150, 600, 260]); 
      win.pnl = win.add("panel", [10, 10, 440, 100], "Script Progress");
      win.pnl.progBar = win.pnl.add("progressbar", [20, 35, 410, 60], 0, 100);
      win.pnl.progBarLabel = win.pnl.add("statictext", [20, 20, 320, 35], "0%");
      
      win.show();
      
                          while(win.pnl.progBar.value < win.pnl.progBar.maxvalue)
                          {
                                    // this is what causes the progress bar increase its progress
                                    win.pnl.progBar.value++; 
                  win.pnl.progBarLabel.text = win.pnl.progBar.value+"%";
                                    $.sleep(10);
                          }
      
          alert('Done!'); 
      
      win.close();

       

      But I am having following error when I run it:

      1.jpg

       

      Can you please tell me why it is happening....

       

      Thanks

      Harsh S

        • 1. Re: Uncaught exception when I update window
          CarlosCanto Adobe Community Professional & MVP

          first, you're just showing 18 lines of code, your error is in Line 422

           

          next, all the code in "Red" in your sample needs to be enclosed in quotation marks

          • 2. Re: Uncaught exception when I update window
            pixxxel schubser Level 5

            @Harsh V Sharma,


            please show your code for the progress bar completely. ( I can't find win.update() in your code). Also this call is only needed, if you work under MacOS. The palette works fine under Windows OS without win.update().

            • 3. Re: Uncaught exception when I update window
              Silly-V Adobe Community Professional

              I am having a similar problem too, but cannot find a way to replicate the problem outside my very convoluted current project..

              • 5. Re: Uncaught exception when I update window
                pixxxel schubser Level 5

                @Harsh V Sharma,

                you have now found a solution? Or you can answer my previous posting?

                • 6. Re: Uncaught exception when I update window
                  Harsh V Sharma Level 1

                  Hi follwing is the  code i am using:

                   

                   

                   

                   

                  function artboardToJPGs(size)
                  {

                      

                  var win = new Window("palette", "SnpCreateProgressBar", undefined, {borderless: true});

                  win.pnl = win.add("panel", [10, 10, 440, 100], "Creating JPEG");

                  win.pnl.progBar = win.pnl.add("progressbar", [20, 35, 410, 60], 0, 100);

                  win.pnl.progBarLabel = win.pnl.add("statictext", [20, 20, 320, 35], "0%");

                          win.show ();
                     

                   

                  for(i=0; i<10; i++)

                  {

                  win.pnl.progBar.value+=10;
                          win.pnl.progBarLabel.text = win.pnl.progBar.value+"%";
                          win.update();


                   

                  }

                   

                   

                          var idx, j, sizes, jpegOpt, doc, docName, dF, artBds, abName, scale, jpgFile, destinationFolder, originalImage;
                         
                          jpegOpt = new ExportOptionsJPEG();
                          jpegOpt.Optimization = true;
                          jpegOpt.QualitySetting = 100;
                          jpegOpt.blurAmount=0;
                          jpegOpt.artBoardClipping=false;
                         
                          dF=new Folder(jpgImageFolder);
                          if ( !dF.exists ) dF.create();

                          doc = app.activeDocument;
                          docName=doc.name;
                        
                          artBds = doc.artboards;
                      
                          idx = artBds.getActiveArtboardIndex();

                          abName = artBds[ idx ].name;


                      
                             var w= artBds[ idx ].artboardRect[2] - artBds[ idx ].artboardRect[0] ;
                             var h=artBds[ idx ].artboardRect[1] - artBds[ idx ].artboardRect[3];

                              var width=  100+ ( (size - w)/w ) * 100;
                       
                              var height=  100+ ( ( size - h )/h ) * 100;

                              jpgFile = File( dF.fsName + '/' + fileName + size + 'x' + size + '.jpg' );
                      
                              jpegOpt.horizontalScale =width;
                              jpegOpt.verticalScale = height;
                              doc.exportFile( jpgFile, ExportType.JPEG ,jpegOpt );
                             
                              win.close();
                         
                  }

                  • 7. Re: Uncaught exception when I update window
                    pixxxel schubser Level 5

                    Sorry, but your code is terrible posted in forum.    …(like my English)

                     

                    I think the counter i is not used in win.pnl

                    And because the steps are defined anyway : win.pnl.progBar.value + = 10;

                    try this:

                    while(win.pnl.progBar.value<100)
                    

                     

                    instead of:

                    for(i=0; i<10; i++)
                    
                    • 8. Re: Uncaught exception when I update window
                      CarlosCanto Adobe Community Professional & MVP

                      your English is great.

                      • 9. Re: Uncaught exception when I update window
                        Harsh V Sharma Level 1

                        Yaar I am posting my code again on this portal:

                         

                        this is terrible because its not working:::

                         

                        • function artboardToJPGs(size)
                        • {
                        •    
                        • var win = new Window("palette", "SnpCreateProgressBar", undefined, {borderless: true});
                        • win.pnl = win.add("panel", [10, 10, 440, 100], "Creating JPEG");
                        • win.pnl.progBar = win.pnl.add("progressbar", [20, 35, 410, 60], 0, 100);
                        • win.pnl.progBarLabel = win.pnl.add("statictext", [20, 20, 320, 35], "0%");
                        •         win.show ();
                        •   
                        • for(i=0; i<10; i++)
                        • {
                        •     win.pnl.progBar.value+=10;
                        •             win.pnl.progBarLabel.text = win.pnl.progBar.value+"%";
                        •             win.update(); 
                        • }
                        •     
                        •         var idx, j, sizes, jpegOpt, doc, docName, dF, artBds, abName, scale, jpgFile, destinationFolder, originalImage;
                        •       
                        •         jpegOpt = new ExportOptionsJPEG();
                        •         jpegOpt.Optimization = true;
                        •         jpegOpt.QualitySetting = 100;
                        •         jpegOpt.blurAmount=0;
                        •         jpegOpt.artBoardClipping=false;
                        •       
                        •         dF=new Folder(jpgImageFolder);
                        •         if ( !dF.exists ) dF.create();
                        •         doc = app.activeDocument;
                        •         docName=doc.name;
                        •      
                        •         artBds = doc.artboards;
                        •    
                        •         idx = artBds.getActiveArtboardIndex();
                        •         abName = artBds[ idx ].name;
                        •    
                        •            var w= artBds[ idx ].artboardRect[2] - artBds[ idx ].artboardRect[0] ;
                        •            var h=artBds[ idx ].artboardRect[1] - artBds[ idx ].artboardRect[3];
                        •             var width=  100+ ( (size - w)/w ) * 100;
                        •     
                        •             var height=  100+ ( ( size - h )/h ) * 100;
                        •             jpgFile = File( dF.fsName + '/' + fileName + size + 'x' + size + '.jpg' );
                        •    
                        •             jpegOpt.horizontalScale =width;
                        •             jpegOpt.verticalScale = height;
                        •             doc.exportFile( jpgFile, ExportType.JPEG ,jpegOpt );
                        •           
                        •             win.close();
                        •       
                        • }
                        • 10. Re: Uncaught exception when I update window
                          pixxxel schubser Level 5

                          @Harsh V Sharma,

                          please read my last post again - carefully.

                           

                          @CarlosCanto