This content has been marked as final. Show 7 replies
Script Tools at 9.3
At 9.3 and earlier script tools have been the main way to provide UI for your python scripts. Also at 9.3 or later, the script tools run in the same process as ArcMap. So script tools are sort of the framework to build UI for python scripts. The script tools allow you to create new geoprocessing tools similar to other system tools in ArcToolbox. Note that the script tools are part of the geoprocessing framework. So they have the same UI as the system tools. They don't provide an event driven programming model that VBA forms are capable of doing. Having said that you can still achieve a lot of UI functionality like browsing to inputs without any code and even complex input validation with some python code (using ToolValidator class).
Have a look at these help topics to know more about script tools. Most of the script tools stuff has been common between 9.3 and 10.
What's new at 10
At 10, as you are already aware, there is the new mapping module with arcpy. However, there is no special UI framework that allows you to create VBA form like interface for python scripts. You still have script tools as the best choice to run your python scripts from within ArcMap. One new feature is that you can take a model or a script tool from your toolbox and create a UI button from it using the Customize dialog. That way you can have a toolbar and the buttons launch the script tools (which have a gp tool UI) and can execute them (no coding necessary for this)
Add in framework
To create VBA form like event driven interfaces, you have to use the Add in framework. Addins can be developed using C#, VB.NET or Java and has the requirement of using Visual studio or Eclipse IDEs. But the add in framework and the IDE support for creating addins makes creating customizations for ArcMap at 10 a lot easier (and we hope you will find it as easy as VBA forms:)).
Hope this helps
In 10, you can add Geoprocessing tools to your toolbars from the Customize window. Any tool that has no parameters will execute immediately when you click its button, giving you a way to get command buttons more-or-less for free with your script tools. You can then code a wxPython or PyQT or TkIinter UI in the geoprocessing script.
Or use clrtypes with IronPython, and run from within c# 4 using dynamic:) and skip arcpy altogether.
@jscheirer - Great idea about putting a wxPython script onto the toolbar but I cannot get this to work.
No matter what I try, the GP executing window always pops up and interferes with the focus of my wxFrame so it doesn't function properly. If I turn off the 'run in process option' then I just get an error.
Have you had any success with this?
Hi there, I was wondering if you or anyone here has found a solution to this UI issue. My Tkinter code runs but I'm not able to enter any text fields due to competing cursor priority.
You can mark the GP tool to run out-of-process in the script tool configuration dialog (uncheck run in process) and the focus contention issue should go away. And I believe PyQT behaves pretty well when run in process, but I have not done extensive testing.
This may be a workaround (apparently until 10.1). I simply wanted to get a Tkinter form to work with an entry box called from a script tool from ArcToolbox. I had interface problems as mentioned earlier in the thread. Focus wouldn't allow me to enter anything in the entry box.
I tried a few things and this seemed to be a fix for now (I only tested on one form). The object of my script was to update a database table in a file geodatabase. I wasn't doing anything with TOC layers, so this solution may not work for you. Also, this could be bad practice, but I was more concerned with the form working to update the database table.
My solution was to create a separate python script that is accessed by a tool, that in turn calls my real tool with the tkinter form. The script launches my real tool from the operating system using os.system. This seems to provide a buffer from interference with ArcMap's GUI.
Here's the code of a separate python program called PyLauncher.py. PyLauncher.py runs my real tool with tkinter forms within the script called UpdtProjectDB.py from the operating system via a seperate process or shell:
runin = os.system("C:\\Python26\\ArcGIS10.0\\python C:\\Tim\\ArcGIS\\TableRelate\\py\\UpdtProjectDB.py")
I add the launcher to my ArcToolbox as a script tool and am then able to interact with the Tkinter form from UpdtProjectDB.py. I have not done any research to see if this might be problematic, so use this technique at your own risk. It's not fast, but in my case it works and I can look forward to the improvements in 10.1.