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

Scripting a Progress Bar only works if total time is < 5 Seconds

Community Beginner ,
Oct 12, 2023 Oct 12, 2023

Copy link to clipboard

Copied

Hi everybody
I am trying to write a simple progress bar script, to use in my other scripts.

// Function to update the progress bar
function updateProgressBar(value, max) {
    var progressBarWindow = new Window("palette", "Progress", undefined);
    var progressBar = progressBarWindow.add("progressbar", undefined, 0, max);
    progressBarWindow.show();
    progressBarWindow.center();
    // Function to update the progress value
    progressBarWindow.updateProgress = function (value) {
        progressBar.value = value;
        this.update();
    };
    return progressBarWindow;
}

// Example usage:

var progressBar = updateProgressBar(0, 100); // Create a progress bar with a maximum value of 100
var startTime = new Date().getTime(); // Get the current time
var duration = 6000; // 5 seconds in milliseconds

while (new Date().getTime() - startTime < duration) {
    // Update the progress bar value based on the elapsed time
    var elapsed = new Date().getTime() - startTime;
    var progress = (elapsed / duration) * 100;
    progressBar.updateProgress(progress);
}
// Close the progress bar window when done
progressBar.close();

this works totally fine for
var duration = 5344
for
var duration = 5345
or more, the script hangs and the progress bar doesn’t close, and is not closeable by hand afterwards.

The same behavior happend when i tried to use in a script which looks in a bunch of layers. If the total time the script needs is under 5 seconds everything works fine, if it needs longer it hangs.

Any ideas on that really strange behavior? I tested on two different computers.
Did somebody have implemented a progress bar in a script and tested if it works fine for longer durations than 5 or 6 seconds? Would be really helpful to know what you did different.

 

TOPICS
Scripting

Views

53

Translate

Translate

Report

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
no replies

Have something to add?

Join the conversation