Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Uncaught exception when I update window

Guest
Oct 29, 2012 Oct 29, 2012

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

TOPICS
Scripting
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Oct 30, 2012 Oct 30, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 30, 2012 Oct 30, 2012

@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().

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 07, 2012 Nov 07, 2012

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();
       
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2012 Nov 08, 2012

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++)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2012 Nov 08, 2012

your English is great.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 08, 2012 Nov 08, 2012

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();
  •       
  • }
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 10, 2012 Nov 10, 2012
LATEST

@Harsh V Sharma,

please read my last post again - carefully.

@CarlosCanto



Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 07, 2012 Nov 07, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 07, 2012 Nov 07, 2012

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 07, 2012 Nov 07, 2012

@Harsh V Sharma,

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines