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!

  • @QZMOPM
    link
    English
    11 year ago

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