[GIS] Making button that calls Python script as command rather than script tool

arcgis-10.0arcpypython-script-tool

I believe that in Arc9.3, commands could be created using VBA scripts. To add a custom command, you would navigate to Customize > Toolbars > Customize… and click UIControls. However, UIControls is not there in version 10.

I am creating two separate scripts for a map book project. One script will save the layout settings to a table, and the other will update the layout with settings from the same table. I want both of these scripts to be commands assigned to buttons in a toolbar. I created them as script tools, but whenever I click on them, they run the script as a geoprocessing tool. It brings up a progress window, and it takes about 10 times longer to execute than if I had run the code in the Python command line window. I don't want the progress window or the much longer execution time.

How can I make it so that the script isn't considered a "tool" and is instead a command similar to the Save button?

Best Answer

Within an Excel VBA macro, the following calls a Python script called test.py:

Sub test()

rsp = Shell(Environ$("COMSPEC") & " /c C:/test.py", vbNormalFocus)

End Sub

(Original source here) I've forgotten how to run an ArcGIS VBA module, but perhaps a similar line would work to call your python script.


Another strategy that might work could be to compile your python script to an executable (.exe) or batch file (.bat) and call it then.


I just saw another answer on gis.se that is more elegant:

Private Sub python_Click()
    Shell "C:\Python25\python.exe ""C:\rowcount.py"
End Sub