[GIS] Waiting for a python script tool to complete while using pythonaddin button

arcgis-10.1arcpypython-addin

I have created a pythonaddin toolbar, with a button that executes a python script tool. This tool is in an ArcToolbox which has been stored in the Install folder of the addin. It executes and runs perfectly. However, the rest of the script in the pythonaddin button class does not wait for the tool to finish. I searched on the ESRI help forums, and there was a suggestion that I use a while loop to wait for the result of the tool. However, I do not believe that a custom python script tool returns a result object like arcpy gp tools.

My toolbar (toolbar_addin.py) code

parameterList = []
class button1(object):
    def__init__(self):
        self.enabled=True
        self.checked=False
    def onClick(self):
        ### Get path to external toolbox
        toolbox = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'Toolbox.tbx')
        ### execute external script tool
        pythonaddins.GPToolDialog(toolbox, 'tool')

        ### wait for result from gp tool
        while len(parameterList) == 0:
            time.sleep(0.2)

        #do something with items from parameterList

My tool (tool.py) code

import toolbar_addin

input1 = arcpy.GetParameterAsText(0)
input2 = arcpy.GetParameterAsText(1)

#do something to create output1 and output2...

toolbar_addin.parameterList = [output1, output2]

Now I get the following error:

Traceback (most recent call last):
File "C:\path\to\addin\toolbar_addin.py", line 229, in onClick
    time.sleep(0.2)
TypeError: GPToolDialog() takes at most 1 argument (2 given)

Any suggestions on how I can force my code to wait on the gp tool?

EDIT: I've modified the fuctioning of my button and script tool to resemble this post. The tool passes parameters to a global list variable "parameterList" in the toolbar.

Best Answer

The behavior of the GPToolDialog function is only documented as follows: Opens a geoprocessing tool dialog box.

The function asks the application to bring up a dialog window, but does not return any status/result object to you. It does not offer any way of directly determining when the tool finishes running or if it gets cancelled.