I came across a small script that opens a window with a progress bar that increases after the completion of every iteration in a for loop. It’s pretty useful in a big macro cycling through many images. Sometimes you just want to know your progress in batch mode. So here is the helpful script (from https://imagej.nih.gov/ij/macros/ProgressBar.txt):

// Progress Bar
//
// This macro demonstrates how to display status
// information and a progress bar in a text window. 
// It uses the Plugins>New>Text Window command
// to open a text window without a menu bar.

  title = "[Progress]";
  run("Text Window...", "name="+ title +" width=25 height=2 monospaced");
  for (i=0; i<100; i++) {
     print(title, "\\Update:"+i+"/"+100+" ("+(i*100)/100+"%)\n"+getBar(i, 100));
     wait(200);
  }
  print(title, "\\Close");

  function getBar(p1, p2) {
        n = 20;
        bar1 = "--------------------";
        bar2 = "********************";
        index = round(n*(p1/p2));
        if (index<1) index = 1;
        if (index>n-1) index = n-1;
        return substring(bar2, 0, index) + substring(bar1, index+1, n);
  }

Note: if you using other nested for loops, ensure that the variable you choose isn’t the same as the one here (i), except of course the for loop you’re actually trying to find track the process of. Happy macroing!

  • MurphysLab@lemmy.ca
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    1 year ago

    Generally I’ve preferred using the showProgress function in ImageJ, since it doesn’t require a new window:

    showProgress(progress)

    Updates the ImageJ progress bar, where 0.0progress<=1.0. The progress bar is not displayed if the time between the first and second calls to this function is less than 30 milliseconds. It is erased when the macro terminates or progress is >=1.0. Use negative values to show subordinate progress bars as moving dots (example).

    showProgress(currentIndex, finalIndex)

    Updates the progress bar, where the length of the bar is set to currentIndex/finalIndex of the maximum bar length. The bar is erased if currentIndex>finalIndex or finalIndex==0.

    • QZM@lemmy.worldOPM
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      Can’t believe I didn’t know about this. Thanks a lot! This should shave several lines off my macros.

  • QZM@lemmy.worldOPM
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    Another small note: You can also adjust this script to include time taken per image and in total. Just using the timestamp commands and some math at the end of the macro spit out in the a userprompt window :)