Select to view content in your preferred language

What kind of UIs are available in Arcpy?

6117
18
Jump to solution
09-04-2014 04:15 PM
PaulHuffman
Frequent Contributor

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.

0 Kudos
18 Replies
IanGrasshoff
Regular Contributor

One other option that I didn't see mentioned is to turn your script into a ArcGIS Desktop Add-in.  This is a little bit more advanced then creating a ArcToolbox script tool, but it does give you the ability to easily work with the ArcMap data frame/display.  It really depends on what you are doing and what need to do with your script.

0 Kudos
curtvprice
MVP Alum

In Arc 10, you can add tools as buttons to the ArcMap / ArcCatalog UI. Addins are really most appropriate when you need the user to be able to interact with the map, layers, etc. Geoprocessing script tools are much more flexible as they can be used in Desktop and Pro, from Python (via arcpy) etc.

IanGrasshoff
Regular Contributor

Yeah..I probably should have read the original post more closely, as Paul said that he read the documentation for creating a python add-in and decided against it. 

I personally have created lots of ArcGIS Python Script tools, and a couple of add-ins.  They both have advantages/disadvantages like everything else.  One other thing that I just remembered (not sure if this still works) but you can/could drag a geoprocessing model into the ArcMap table of contents as a "Tool Layer".  It would then allow you to run the model from the ArcMap table of contents.  I used this a couple of times and it worked decent, still the python script tool is probably best if you don't need to access a users map click coordinates.

0 Kudos
PaulHuffman
Frequent Contributor

I thought the idea with script tools was that I could zip up a toolbox containing my script tool and sent it to a colleague. But when I try it, the toolbox unpacks at the destination and the tool source still references the python script in its old absolute path.  What is the correct way to distribute script tools? 

0 Kudos
DanPatterson_Retired
MVP Emeritus

There is an option to use relative paths in the toolbox properties  see Absolute and Relative Paths in Script Tools

AlexanderNohe1
Honored Contributor

You could import the script into the toolbox.  This would allow the script to stay with the toolbox when moving it from user to user.

PaulHuffman
Frequent Contributor

Thanks, I missed that somehow.  That worked for me.  I had started working on a python toolbox, but this is much easier.  This also answers another question I had, How can my user get the script out of the toolbox to see how it works and maybe make slight changes. 

0 Kudos
AlexanderNohe1
Honored Contributor

They can then right click on the script tool and select edit.

PaulHuffman
Frequent Contributor

This my project in a 10.2 toolbox and a 10.x toolbox.  Hey, I thought this new forum had a place to attach zipped files.  Well, I can make a link to Dropbox.  https://dl.dropboxusercontent.com/u/9369478/ClipLidar.ziphttp://   Oh, maybe I just had to get to the advanced editor in this forum.

The project was to export just an area of a LIDAR job by walking the directory tree of a LIDAR job, find tifs, shapefiles, and grids, clip them to an area of interest, and write them out with the same directory tree structure as the input folder,  and make it run in 10.0 so without da.walk.  There is some repeated code doing the clipping for each data type that might have been done in a function for extra style points, but each data type is a little different. Changed my script enough so two arguments are set by GetParametersAsText.  I thought about setting env.overwriteOutput as an option in the dialog box, but then decided I always want to overwrite.  Figured out how to add arcpy.AddMessage for some of the print statements I had to monitor progress.

I also figured out how to get Desktop Geoprocessing Options set so right click>edit goes to IDLE.  I like this environment.

0 Kudos