3

I am trying to use pythonaddins.ProgressDialog in a Python add-in. I am on ArcGIS 10.4.

I will need to perform several steps that will take some time. To show how much work is done, I plan to use a progress bar which is available with the pythonaddins.ProgressDialog.

Trying to run this sample code in the Python window in ArcMap (taken from the Esri help page):

import pythonaddins
with pythonaddins.ProgressDialog as dialog:
    dialog.title = "Progress Dialog"
    dialog.description = "Copying a large feature class."
    dialog.animation = "File"
    for i in xrange(100):
        dialog.progress = i
        time.sleep(0.125)
        if dialog.cancelled:
            raise Exception("Ooops")

The code works fine unless you increase the step in the xrange() from 1 to something bigger. For instance, if you have 10 feature class to copy, it would make sense to make a step of 10 units (100 / 10) so every increase in the bar would correspond to a copied item.

However, I am observing inconsistent drawing of the progress bar. Try running this code in Python window in ArcMap, in a Python add-in or in a script tool.

with pythonaddins.ProgressDialog as dialog:
    dialog.title = "Progress Dialog"
    dialog.description = "Copying a large feature class."
    dialog.animation = "File"    
    for i in xrange(0,100,10):
        dialog.progress = i
        time.sleep(0.5)        
        if dialog.cancelled:
            raise Exception("Ooops")

This is how it looks on my machine. As you can see, the progress bar is jumping back and forth. I've tried multiple steps (2,5,10,20) and observed the same behavior: as long as the step is not 1, the bar jumps back and forth in progress.

enter image description here

Has anyone seen this and know if there is any workaround for this?

  • @PolyGeo, out of curiosity, why did you remove the arcgis-desktop and python tags? I do run Python code inside ArcGIS Desktop, makes sense to me. arcpy tag you've added, on the other hand, I don't use at all. – Alex Tereshenkov Nov 1 '16 at 7:26
  • Technically the pythonaddins module falls outside the ArcPy site package but to try to keep the tagging scheme simple I group them together for tagging purposes. That way those who are only able to answer ArcGIS GUI questions just filter for arcgis-desktop and those able to answer ArcGIS (Python) coding questions just filter for arcpy. I see it as a pragmatic rather than purist approach. – PolyGeo Nov 1 '16 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.