Select to view content in your preferred language

Run Python script from toolbar button

5091
7
06-06-2012 12:11 PM
RaymondGoins
Regular Contributor
Is it possible to attach a Python script directly to a button? I have created a custom toolbox and added the script to the toolbox and then added the tool to a button in the toolbar. But the problem is I don't want that box to come up when you run a tool. I would like to have my own messages and boxes come up.

I had these script working in vba but I am converting my scripts to python and now having this issue.

Is this possible??

Ray
Tags (2)
0 Kudos
7 Replies
MathewCoyle
Honored Contributor
I believe you can execute a python script through a .NET button using ArcObjects. Don't ask me how though, and I don't think it is really supported by Esri.

Similar discussion here recently.
http://forums.arcgis.com/threads/58207-ArcPy-and-Tkinter
0 Kudos
NobbirAhmed
Esri Regular Contributor
You cannot pop up your own messages/boxes in 10.0 😞

However, you can add the script tool to your toolbar from Customize > Customize Mode ... > Commands tab - see the screenshot below:

[ATTACH=CONFIG]14993[/ATTACH]

In your script, you can add messages using the arcpy.AddMessage(..) and/or arcpy.AddError(..) calls.
0 Kudos
AzharIbrahim
Occasional Contributor
I can add the tool to my custom toolbars, but the next time I open a new ArcMap document, the custom toolbars are there, but the tools are missing. The only way that I've been able to keep the python script tools on my toolbars is to save to the mxd. I would like to have them available always, not just when I open that particular mxd. (I'm using Windows XP, ArcGIS 10.0 SP3)
0 Kudos
NobbirAhmed
Esri Regular Contributor
I'm afraid the only way is to use the saved map document 😞 I'll check again and let you know.
0 Kudos
NobbirAhmed
Esri Regular Contributor
Update - check out this document:

Fundamentals of saving your customizations

Looks like you cannot do it without saving the document. At the middle of the topic it states that:

The customizations listed below are only ever saved at the document level; you cannot elect to save these customizations in your template.
�?�UI Controls added to any toolbar or menu
�?�Macros added as buttons to any toolbar or menu
0 Kudos
AlexeyTereshenkov
Deactivated User
Have you looked at new Python Add-ins available in 10.1? It seems as you can do a whole lot with them however no dockable windows and no custom UI support available. I guess ability to have individual message window(s) when running the script might be added in later editions of Python add-ins, so keep your eye on them.

Overview of Python add-ins video
0 Kudos
AzharIbrahim
Occasional Contributor
I created a toolbox and added script tools using my python scripts. I then added this new toolbox to my regular toolbox and saved the settings to default so that the toolbox is always there. I would have liked to have a custom button that was always there like my add-ins, but this works for now.
0 Kudos