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

How can add a progress bar into script?

Explorer ,
Jul 29, 2014 Jul 29, 2014

Hi,

I got a script for gen pdf

I want put a progress bar, and make it working

but I don't know where I can put the progress bar

and how

//=====================================================================

var doc = app.documents; 

app.findTextPreferences = null; 

app.findTextPreferences.underline = true; 

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

        var found = doc.findText(); 

        var _pages = []; 

        for(var j=0;j<found.length;j++) 

        { 

                var txfms = found.texts[0].parentTextFrames; 

                for(var k=0;k<txfms.length;k++) 

                { 

                        _pages.push(txfms.parentPage.name); 

                    } 

            } 

        for(var j=0;j<_pages.length;j++) 

        { 

                if(_pages === _pages[j-1]) 

                { 

                        _pages.splice(j,1); 

                    } 

            } 

        if(_pages.length != 0) 

        { 

                app.pdfExportPreferences.pageRange = _pages.toString(); 

                doc.exportFile(ExportFormat.PDF_TYPE, new File(doc.fullName.toString().replace(/\.indd$/i,".pdf")), false); 

            } 

        _pages = []; 

    } 

//=================================================================== Can I put progress bar in here?

           var counter = new Window("palette");

           counter.prompt = counter.add("statictext",[0,0,80,20]);

           counter.show();

           var cells = app.activeDocument.allCellStyles;

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

           counter.prompt.text = String(i);

           cells.verticalJustification = VerticalJustification.bottomAlign;

           }

           counter.close();

//===================================================================

app.findTextPreferences = null;

alert("Done.");

thanks

Harvey

TOPICS
Scripting
701
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 ,
Jul 29, 2014 Jul 29, 2014

Progress bars are described here: http://www.kahrel.plus.com/indesign/scriptui.html

Peter

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
Participant ,
Jul 29, 2014 Jul 29, 2014

Hi harvey,

you can add this code in "front or back" part of your script, try this

main();

function main(){

      var progress_win = new Window ("palette");

var progress = progress_bar(progress_win, 2, 'Processing ... Completed');

    delay(1);

      progress.value = progress.value+1;

    delay(1);

    progress.parent.close();

    }

// delay function found here

//found here http://www.wer-weiss-was.de/theme157/article1143593.html

  function delay(prmSec){

  prmSec *= 1000;

  var eDate = null;

  var eMsec = 0;

  var sDate = new Date();

  var sMsec = sDate.getTime();

  do {

  eDate = new Date();

  eMsec = eDate.getTime();

  } while ((eMsec-sMsec)<prmSec);

  }

/**

* Taken from ScriptUI by Peter Kahrel

*

* @param  {Palette} w    the palette the progress is shown on

* @param  {[type]} stop [description]

* @return {[type]}      [description]

*/

function progress_bar (w, stop, labeltext) {

var txt = w.add('statictext',undefined,labeltext);

var pbar = w.add ("progressbar", undefined, 1, stop);

pbar.preferredSize = [300,20];

w.show ();

return pbar;

}

by

hasvi

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
Enthusiast ,
Jul 30, 2014 Jul 30, 2014

Hi Harvey,

Try this,

var doc = app.documents;

app.findTextPreferences = null;

app.findTextPreferences.underline = true;

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

{

        var found = doc.findText();

        var _pages = [];

        for(var j=0;j<found.length;j++)

        {

                var txfms = found.texts[0].parentTextFrames;

                for(var k=0;k<txfms.length;k++)

                {

                        _pages.push(txfms.parentPage.name);

                    }

            }

        for(var j=0;j<_pages.length;j++)

        {

                if(_pages === _pages[j-1])

                {

                        _pages.splice(j,1);

                    }

            }

        if(_pages.length != 0)

        {

                app.pdfExportPreferences.pageRange = _pages.toString();

                doc.exportFile(ExportFormat.PDF_TYPE, new File(doc.fullName.toString().replace(/\.indd$/i,".pdf")), false);

            }

        _pages = [];

    }

    var counter = new Window("palette");

    counter.prompt = counter.add("statictext",[0,0,80,20]);

    counter.show();

    var cells = app.activeDocument.allCellStyles;

  

    var w = new Window('palette');

    w.pbar = w.add('progressbar', undefined, 0, cells.length);

    w.pbar.preferredSize.width = 300;

    w.show();

    w.pbar.value = 0;

  

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

    {

        w.pbar.value += 1;

        counter.prompt.text = String(i);

        cells.verticalJustification = VerticalJustification.bottomAlign;

    }

    counter.close();

app.findTextPreferences = null;

alert("Done.");

Regards,

Chinna

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
Explorer ,
Jul 31, 2014 Jul 31, 2014
LATEST

Hi, Chinna

thank you for your help

but the progress bar not really work

may be the progress bar need to put at beginning

Harvey

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