12

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?

2 Answers 2

6

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
3

I'm a complete GIS newb, but I came across this in the documentation:

You can make your script tools run faster by running them in process. This topic describes in-process execution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.