I've been writing some python scripts for colleagues that get stuff done, but I'm forced to have the users edit the scripts to insert the data paths and file names for their situation. The best user interface I can come up with is to put these user editable variables up in a section near the top of the script. I've been looking around for a way to make user interfaces more slick, like a VB browse to data box that would allow the user to browse their directories for their input files, but haven't found the correct place. I snooped around in the docs for Python Add-ins, but decided that is not what I'm looking for. http://video.esri.com/watch/2288/developing-python-add_dash_ins-for-arcgis-desktophttp:// at 3:08 pretty much tells me there is no custom UI support in python add-ins.
Solved! Go to Solution.
Why don't you turn the script into a scripting tool. This will allow the users to add parameters using a GUI which is available in ArcToolbox.
ArcGIS Desktop Help 9.3 - An overview of creating script tools
Why don't you turn the script into a scripting tool. This will allow the users to add parameters using a GUI which is available in ArcToolbox.
ArcGIS Desktop Help 9.3 - An overview of creating script tools
I think this is what I was looking for, except I'm using 10.2.2 so I found the corresponding help pages for my version. Reading the Docs now and went through the Add Script dialog. But I need to understand better the "Setting Script tool parameters" because I haven't figured out how I set a tool parameter to replace the input FCs that my python script now sets as variables from strings in the script e.g. InputFolder = "c:\\avdata\\PythonTest\\ClipLidar\\TestData\\Input"
Check the help files on GetParameterAsText (or sys.argv in pure python) In your script you will set your input parameters as such, then in the toolbox, you give it the type. For example, here are snippets from one of my scripts and how I establish the association between the inputs and how the tools parameters need to be identified.
''' Properties: (right-click on the tool and specify the following if creating your own tool) General Name mxdInfo Label mxd Information Desc Project information focusing on table of contents and data therein Parameter list Parameter Properties Display Name Data type Type Direction MultiValue Dependency argv[1] Select a project Arcmap document Required Input No argv[2] Output textfile Text file Optional Output No argv[3] Include env ... Boolean Optional Input No '''
....... The above is part of the header section, the next is the first few lines of the actual script
import sys import arcpy import textwrap arcpy.env.overwriteOutput = True #for toolbox mxd = sys.argv[1] #Notice that sys.argv[1], or arcpy.GetParameterAsText(0) is a project output_file = sys.argv[2] #sys.argv[2] is an output text file envBoolean = sys.argv[3] # a Boolean indicating whether environment variables are to be included
This was what I should have been reading too: Accessing parameters in a script tool
Worked great. Look, I'm a developer now!
Paul, do dig into parameter validation, this allows you quite a bit of capability to guide your user to get the right inputs in place -- BEFORE they click OK and run the tool. I have used this to make a script tool with more than 15 parameters amazingly easy to use. Of course this is all covered pretty well in the help both for toolboxes and python toolboxes.... However, if you want to check it out as a real-world example of what I'm talking about, see my presentation from the Esri UC, A flexible Python script tool for stratified random site selection.
This toolbox has been posted in GitHub: https://github.com/cprice-usgs/USGS_Sample
I definitely agree with Jerry on this one. It removes the need for other people to have anything else installed on their computers.
Hi
One
more way is to add a text file with all the data needed in the same disk location as the python script.
This is very similar to the cfg file for other software.
If Python didn't run in some funky sandbox, you could use Tkinter. Last time I checked, if you clicked a button, the GUI died. C# has a System.Diagnostics.Process.Start()
which could possibly be used in your GUI to execute your scripts and pass parameters. It works fine on the desktop but I have never tried it in ArcMap.
I have seen a very successful implementation of setting up a standalone .exe in an independent process which is launched synchronously from Python - using the subprocess module. This could be done with a TkInter Python script as well to "insulate" your arcmap session from the GUI data collection.
However, I agree with Dan Patterson that in most situations, working within the out of the box GUI tools provided with ArcGIS is best because users don't need to navigate a new UI - they can use the tool UI they are used to (either in ArcGIS Desktop, or soon, in Pro). Let Esri do the work on this one!