Copy link to clipboard
Copied
Hi All,
How to add progress bar in script. I have gone through with forums but couldn't find any simple example.
Could anybody please show me a simple js code with progress bar in indesing script.
Thanks in advance for your support.
Mon.
Copy link to clipboard
Copied
It's described in this guide: http://www.kahrel.plus.com/indesign/scriptui.html
But it may not be that easy.
Peter
Copy link to clipboard
Copied
http://forums.adobe.com/search.jspa?communityID=3331&resultTypes=MESSAGE&q=progress+bar
(Or did you mean that none of the answers you found are easy?)
Copy link to clipboard
Copied
I have refered these sample scripts
http://www.adobe.com/products/indesign/scripting/
choose
> Scripting Resources > InDesign CS5 in-depth scripting guides
and download
Download the InDesign Scripting Guide scripts (ZIP, 832k )
unzip it, if javascript, progressbar sample is here
indesign_cs5_scripting_guide_scripts
āāā javascript
ā āāā userinterfaces
ā ā āāā progressbar
ā ā āāā CallProgressBar.jsx
ā ā āāā ProgressBar.jsx
you can also download other fuction scripts
mg
Copy link to clipboard
Copied
Thanks you all for your answer.
I have gone through with your suggestion. But it seems not easy for me.
Could you please help me to add the progress bar in below simple script.
Thanks,
Mon
Here is my script code.
var myFilePath = Folder.selectDialog("Please choose files:");
myFilePath = new Folder (myFilePath);
myFilePathContents = new Array();
mySubFolders(myFilePath);
var myDocument = app.documents[0];
for (var j = 0; myFilePathContents.length > j; j++) {
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
var myDocument = app.open(myFilePathContents
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
//
myDocument.viewPreferences.horizontalMeasurementUnits =MeasurementUnits.millimeters;
myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.millimeters;
app.activeDocument.close(SaveOptions.yes);
//
}
function mySubFolders(theFolder) {
var myFileList = theFolder.getFiles();
for (var i = 0; i < myFileList.length; i++) {
var myFile = myFileList;
if (myFile instanceof Folder){
mySubFolders(myFile);
}
else if (myFile instanceof File && myFile.name.match(/\.indd$/i)) {
myFilePathContents.push(myFile);
}
}
}
alert("Done.")
Copy link to clipboard
Copied
Please help me out to add the progress bar in this script.
Thanks in advance,
Mon
Copy link to clipboard
Copied
Here the sample coding.... and u have to change based on ur script.
var list = ["one", "two", "three", "four", "five", "six"];
var w = new Window ("palette","Progress Bar");
var progress = progress_bar (w, list.length);
for (var i = 0; i < list.length; i++)
{
progress.value = i+1;
// user functions
$.sleep (400);
}
progress.parent.close();
function progress_bar (w, stop)
{
var pbar = w.add ("progressbar", undefined, 1, stop);
pbar.preferredSize = [300,20];
w.show ();
return pbar;
}
Copy link to clipboard
Copied
@Cenchen ā are you on Windows or on Mac? Frankly I had no luck with your codeā¦
I'm on Mac OSX 10.6.8 and just tested with InDesign CS5.5.
Result:
The palette will show up, showing the first sixth of the progress bar, but will not change any further. After a while (I think after the $.sleep(400) is executed six times) it will closeā¦
A progress bar that unfortunately shows no progress (screen shot):
Of course I added a #targetengine in the codeā¦
The question is: how can we force the progress bar to be redrawn if it does not?
One could add a new palette window every time the loop iterates, but that will become a flickering effect on the user side and adds up a lot of time in the overall speed of the script.
Uwe
Copy link to clipboard
Copied
Here I am adding a script snippet that will show a new progress bar every time the for loop iterates.
It's downside is that it would be very slow in a real world scenario:
#targetengine "sessionProgressBar1"
var list = ["one", "two", "three", "four", "five", "six"];
var counter = 0;
for (var i = 0; i < list.length; i++){
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
++counter;
var w = new Window ("palette","Progress Bar");
var pbar = w.add("progressbar", undefined, counter, list.length);
pbar.preferredSize = [300,20];
w.show();
$.sleep (400);
if(counter === list.length){w.close();};
};
alert("Showing the window "+counter+" times.");
If you take that approach for a large quick iterating loop (without the $.sleep), you'll get a big performance problem and a flickering palette window ā¦
Uwe
Copy link to clipboard
Copied
In my first tests I also added the line with the:
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
But that makes no difference. On my OSX 10.6.8 the progress bar of the first version will not change.
Only building a new palette window every time the loop is iterating has worked (for me).
Uwe
Copy link to clipboard
Copied
Uwe,
if you set enableRedraw to false, progress bar will stop updating.
--
Marijan (tomaxxi)
Copy link to clipboard
Copied
@Marijan ā great! That was it.
Somehow, maybe some scripts executions ago, I must have set "enableRedraw" to false.
Thanks a lot!
Uwe
Copy link to clipboard
Copied
I should have read Peter Kahrel's "scriptui-2-0.pdf" more thoroughly.
On page 52 there is a sidenote saying:
Note: in scripts that use progress bars, you cannot set
app.scriptPreferences.enableRedraw to false. If you do, the progress
bar doesn't display correctly. This is on Macs only.
Of course that will also affect scripts that should run on both systemsā¦
Uwe