Implement Progress Bar and Abort Lengthy Process

The time has come to talk of many things: of shoes and ships, and sealing-wax, of cabbages and kings [^]... or no, let's continue sticking to the Revit API for now, more or less; today's topics are:

A Walk in the Snow

I went for a walk in snow and fog on a local hill and appreciated this wind-driven ice crystal covered baby tree that:

Wind-driven ice crystal covered baby tree

I thought I would like to share that with you. Sorry that it is so dark, but that's the way it was.

Implementing a Revit Add-in Progress Bar

I chatted with Harry Mattison on various topics during the winter break. One of them was the implementation of a Revit add-in progress bar:

Question: I am trying to make a simple progress dialog based on your post on modeless dialogues. It seems to work well basically but has a few problems:

  1. The first time I run the command, the progress dialog flashes briefly on the screen and then disappears.
  2. The text label does not display properly.
  3. Sometimes the entire progress dialogue content turns white and the title bar says 'Not Responding'.

Could you help me figure out if my approach is flawed or if it just needs some small adjustments?

Answer: Thank you, but no thank you... :-)

Instead, I propose that you look at my existing modeless progress bar implementation in the ADN Revit MEP sample add-in, which has worked flawlessly for years now.

Response: Your progress bar is great! I wish I had found it earlier.

Aborting a Lengthy Process

Here's hopefully one last question about the progress bar:

How can the user cancel the operation from the progress bar?

Answer: You could implement some standard .NET stuff on the progress bar; maybe simply add a cancel button to it, and an event handler for that.

Response: After spending some time thinking about events and the like, I realized the progress bar cancel solution is almost trivial.

An idle event wouldn't work in my case, because Revit was never going idle. It was too busy doing hard work of exporting images for my Image-O-Matic application. Instead, all I needed to do is add the Abort button to the progress dialog, and put this little bit of code in the progress bar class:

  private void btnAbort_Click(
    object sender,
    EventArgs e )
    btnAbort.Text = "Aborting...";
    abortFlag = true;
  public bool getAbortFlag()
    return abortFlag;

Then, inside my foreach loops, I just need to check the status of the flag:

  foreach( string phaseName in phaseList )
    if( progressForm.getAbortFlag() )
    // . . .

Many thanks to Harry for the fruitful discussion and helpful hint!

Image Generation Video Competition

Yet another item from Harry, this time a rather shameless plug, but I guess he earned it :-)

Harry announced a competition in which you can win a free, custom-built Revit API add-in according to your own specifications for downloading his Image-O-Matic application, generating a video with it, and uploading that to YouTube.

Have fun, and good luck to you!