From time to time we like to feature guest posts. Today I’d like to draw your attention to a tutorial from Bob Roberts at the Python and Then Some blog. We’re going to be re-posting several of Bob’s tutorials. I think you’ll find them quite helpful. The first post will teach you how to add a Python script to a toolbar in ArcView 9.3.1. You could easily apply the same concept to ArcGIS 10.0. And now…more from Bob.
So you finished your Python ArcToolbox tool and now you want to add a shortcut to the toolbar. This tutorial is based on the assumption that you have already added your script to the ArcToolbox tools. If not I will cover that in another tutorial. I will show how to add a button in addition to how to add a menu to ArcView toolbar. Both are convenient ways to launch your Python script tools without having to open ArcToolbox.
First we will create a button to launch your tool.
Now that you have a new and empty toolbar we need to create the button for the Python tool.
Now that the button is one the toolbar, we need to set it up to launch your Python tool.
Now that we have the button on the toolbar and changed the way that it displays, it is time to add the Visual Basic snippet to launch the tool.
There are a few things that can cause the button not to open your Python tool. The most common that I have seen is that the Visual Basic reference is not selected as available for using the ESRI GeoprocessingUI Object Library. This can be added by going into the Visual Basic editor again. At the top there is an option for Tools and then select references. Make sure that the ESRI GeoprocessingUI Object Library is checked. If not, check it to make the library available.
If you want to add a drop down menu for listing multiple Python tools the steps are mostly the same. After creating a new toolbar, you can create a new menu before you create the tool buttons.
On the Customize > Commands tab in the left hand pane there is an option for [New Menu]. Create the new menu in the same manner as creating the UIControls button. Add the menu to the toolbar and then you can add tool buttons to the drop down menu by clicking and dragging them to the drop down.
Hope that helps!
Additional Python and ArcGIS tutorials:
The next session of our instructor guided, Internet based course Programming 101 for ArcGIS 10: Mastering Python begins February 21st, 2011. We still have a few seats available. A self-paced version of this course is also available.
Eric Pimpler February 10th, 2011