Select to view content in your preferred language

Attach a Python script to a button?

4649
6
12-02-2010 10:23 AM
MikeDriver
Emerging Contributor
Can you attach a python script to a button?  Instead of adding it as a script tool?  Can you create a whole toolbar of python scripts?
0 Kudos
6 Replies
JoeVondracek
Regular Contributor
I have been unable to find a way to do this without using VBA or .NET.  Of course, VBA is deprecated in ArcGIS 10, so you shouldn't base development on it.  And if you are going to write code in .NET, then you might as well incorporate whatever it is that the Python scripting is doing into the .NET code.

If there is a way to directly launch a Python script from an ArcMap interface button without first turning that script into a Script Tool in a toolbox, then I would also like to know how to do it, but I have combed through the help docs and been unable to discover a way to do this.
0 Kudos
DanPatterson_Retired
MVP Emeritus
what is the aversion to using tools in ArcToolbox?  they add the extra dimension of being used in models etc and the toolboxes and scripts are easily distributed...the only difference is clicking a button versus clicking a tool in terms of the interface
0 Kudos
JasonScheirer
Esri Alum
Geoprocessing tools with no arguments will be immediately executed (no GP dialog) from toolbar buttons. So if you 1. create a toolbox with a single script tool (no parameters) that points to your .py and 2. customize a toolbar and add a script tool, you should essentially get what you're looking for.
0 Kudos
JoeVondracek
Regular Contributor
It's not a big deal to turn the Python script into a Script Tool, add it to a Toolbox, and then reference it in an ArcMap interface customization from the Toolbox.  However, we have moved from a paradigm where you could have a VBA customization embedded within the MXD project file to one where, in order to do the exact same thing, you need to have at least two additional files: the Python script and the Toolbox.  That changes deployment, and it adds the additional step of creating the Toolbox Script Tool.  Having the tools in a Toolbox means that users can possibly run them outside of the environment that we want them to run them in... unless we spend additional time creating the tools to prevent that, which we wouldn't have to do if they were embedded directly into the MXD project. 

For us, this is mainly a transitional problem in going from an ArcGIS 9.x environment with embedded VBA code in a special MXD project to a world where users (with limited ArcGIS skills) are split between versions 9.x and 10, and you can't quite do things in the same manner between those two versions.
0 Kudos
SeanCook
Emerging Contributor
To all ESRI personnel reading this, I would like to voice that I also find this very annoying.
0 Kudos
NiklasNorrthon
Frequent Contributor
Are you aware that you can embed your python scirpts in the toolbox? See http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Embedding_scripts_and_password_protect... for details.
0 Kudos