Interactive Python toolbox

3050
8
Jump to solution
06-27-2016 11:45 AM
PaulHacker2
New Contributor II

I constructed a Python Toolbox that has many steps. When one first runs it a window comes up and for the layers and folders and shapes, the boxes for the information show up well.

BUT, for each stage of the run I want it to display results and ask if one wants to continue.

Tkinter does NOT work for this (tried and tried.) And the arcpy.AddMessage does not seem to be suitable as it's a message and not being able to handle input like (Y/N) to continue.

I would like the original box to say visible and the messages show up on the bottom.

Is this possible with ArcMAP/ArcGIS?

Thanks.

0 Kudos
1 Solution

Accepted Solutions
FreddieGibson
Regular Contributor II

Note that the pythonaddins module is not intended to be used outside of addins.

pythonaddins.png

Are you by any chance familiar with ArcObjects? Also, if the tools are successful would there be a valid reason for the user to stop the execution of the next tool?

View solution in original post

8 Replies
DanPatterson_Retired
MVP Esteemed Contributor

Tk definitely doesn't behave well with Arc*... and I wish there was a way to fix this.  Python or conventional toolboxes don't to the degree you want so I suspect it would be arcobjects or a rethink of your workflow.  Perhaps you could parse it into a couple of smaller tools, for instance, one to provide base information  before the workflow begins, then another to actually do the work.  The user could choose to just see the background and stop or continue on to the actual workflow or they could skip the background and just do the workflow.  This scenario may actually save the user time, particular for repetitive tasks using the same data

PaulHacker2
New Contributor II

Looks like I'll do that. The three steps become three tools on ONE Toolbox. At the end of each a message that will tell the user the step completed with or without errors and point to the next tool.

Or... I could make a VisualStudio with Python or C# (but that would take quite a rewrite.)

Thanks.

0 Kudos
WesMiller
Regular Contributor III

Have you thought about using a python addin for your work flow?

import pythonaddins
pythonaddins.MessageBox('Continue', 'INFO', 3)
PaulHacker2
New Contributor II

So if I use the messagebox it will halt the code till one presses 'continue' button and then it will keep running?

Can a 'cancel' be added so it stops processing.. ah.. looks like OK/Cancel is '1' and 3 is 'yes/no/cancel'. So I guess it does halt the code!

Yes I bet this will do just what I want.

Today is experiment day.

Thanks! Have a good 4th of July guys.

WesMiller
Regular Contributor III

You may want to try something similar to below

import pythonaddins,sys
val = pythonaddins.MessageBox('Continue', 'INFO', 1)
try:
    if val == 'Cancel':
        sys.exit()
except:
    pass
FreddieGibson
Regular Contributor II

Note that the pythonaddins module is not intended to be used outside of addins.

pythonaddins.png

Are you by any chance familiar with ArcObjects? Also, if the tools are successful would there be a valid reason for the user to stop the execution of the next tool?

PaulHacker2
New Contributor II

Works perfect. Thanks Guys!

0 Kudos
ClintonDow1
Occasional Contributor II

In a nutshell, putting any extra UI functionality into an ArcGIS tool is an antipattern, as the tools are designed to be portable within ArcGIS and usable from stand-alone Python.

 

If you have a workflow which necessitates user input, this is a natural place to break the workflow up into multiple tools. Before the input step, write your data and use that data as the input for the next tool, (Deciding to move forward is essentially the Yes/No dialog in your case). This increases modularity of your tools and ensures that they can be accessed arbitrarily from any view - ArcGIS Desktop, Server or from a Python command line. Right now you'll get errors if you try to run outside of desktop and your tool is not portable between 10.x and Pro.

 

Breaking it up like that also has the added benefit of future-proofing the workflow - say somewhere down the line someone invents a process which removes the need for user input, you can simply string your modularized workflow together in a 'wrapper' style tool, rather than recoding the entire thing.

 

Hope that helps move things along!

Clinton