Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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.

share|improve this answer
    
+1 for the answer, but I am really trying to determine if the tool can be run synchronously. –  Barbarossa May 13 '14 at 16:30
    
I implemented that function. It does run synchronously up until 10.2.1 or so when I had to change it to run async to enable interactive selection in the dialogs for feature set inputs. The function was only designed to pop up a tool dialog, not give any feedback. How/when it runs is an implementation detail. –  Jason Scheirer May 13 '14 at 16:44
    
Thanks again, I'm trying to see if the tool, not the dialog, can be run synchronously. –  Barbarossa May 13 '14 at 16:47
    
You cannot force your code in an add-in event to wait on the tool as it is popped up from GPToolDialog. You cannot communicate with the result object like you can when you call the tool directly from Python. You will need to look into other control flow constructs to get your desired behavior. –  Jason Scheirer May 13 '14 at 16:50
    
Understood, please see my edit. –  Barbarossa May 13 '14 at 16:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.