Select to view content in your preferred language

Python code w/ GUI trouble with MapDocument setting.

759
7
08-17-2011 11:28 AM
PatrickJurgens
Deactivated User
I have a python code that I wrote to make updates to a file GDB in an .MXD.

The python code includes a GUI that I programed using Tkinter.

The code (hence forth referred to as the GUI) is designed to conflate attributes from a set of large polygon entities (A) down to a separate set of small polygon entities (B). A list on the left side of the GUI shows which B-entities are still missing attributes. The user double-clicks the B-entity to select it, zoom to it, and populate a list of neighboring A-entities. The user may then select the desired A-entity to have its attributes calculated into the selected B-entity.

When I use the GUI as a stand alone program outside of Arcmap I am forced to reference the specific path of the mxd: mxd = arcpy.mapping.MapDocument('C:/folder/project.mxd')
This allows the GUI to access the correct mxd, however changes made to the MXD are not updated in the ArcMap window (I have project.mxd opened in ArcMap). The goal is to have the GUI update the ArcMap window as it goes so that the user has a visual confirmation of what he is doing.

Alternatively I can run the GUI as a geo-processing script (in the foreground) through a customized button on the standard toolbar.
This has the advantage of allowing me to use the "CURRENT" MapDocument. When I use this method the Map is updated whenever actions are made in the GUI.
The problem with this is that when GUI is run as a geo-processing script is does not allow the user to interact with the Map document (cannot use the pan, zoom, select, or other buttons on the standard toolbar). The user is stuck using only the limited capabilities built into the GUI. Also, when i terminate the GUI it takes ArcMap down with it.

Is there some way that I can execute the GUI outside of ArcMap and still have it update changes to the ArcMap screen?

OR

Is there some way that I can execute the GUI from withing the ArcMap environment without having it block all other essential function in the Map Window?
Tags (2)
0 Kudos
7 Replies
StacyRendall1
Frequent Contributor
Patrick,

not sure if there is a solution for you...

ArcMap doesn't like you to run a tool as well as do anything; as far as I know there is no way around that.

When executing outside ArcMap, what happens if you use the 'Refresh the active view' button (bottom left of the map display)?

Otherwise, what about Refresh on the .mxd in the Catalog view, or opening the .mxd again? I know these would be quite a pain, but not sure what else you can do...

Let us know how you get on!
0 Kudos
PatrickJurgens
Deactivated User
Thank you for replying StacyRandal.

I was starting to get the idea that I may not have a good way to fix this, but it is good to have a second opinion first.

I have tried those other refresh ideas already.

When using the GUI outside of the ArcMap environment the refresh command inside of ArcMap does not register changes in view extent, and does not register changes in Selections sets. The refresh command in ArcMap does register any changes that the GUI has made to the layer, but in order to make changes (correctly) the user should be able to see what they are changing first.

The refresh command in ArcCatalog does not seem to have any effect on the display in ArcMap.

Opening and closing the MXD has the same effect as using the refresh command in ArcMap. Display and Selection changes are not registered, but changes to the actual stored data in the layer are registered. I suppose I could force this method to work by replacing all lines of arcpy.RefreshActiveView() with mxd.save(), where mxd is my map document. I expect this would slow down the code, and as you mentioned, it would be inconvenient to the user.

The reason why I want the ArcMap screen to be enabled at the same time as the GUI script is so that users can augment the selection of polygons that are targeted for editing. The GUI is configured to handle each polygon individually, but when it makes changes they take effect on all selected items. In some (perhaps many) cases I expect the user to see places where their work would be sped up by having the ability to multi-select polygons for correction, rather than zooming to each of them individually. This is not accomplished by using the open/close/reopen method of refresh.

At this point I think it is probably best if I accept it, and if it really bothers me, then i should learn to program full fledged extension using arc objects.
0 Kudos
MathewCoyle
Honored Contributor
Editing an mxd outside of ArcMap, while that mxd is open in ArcMap, is not an easy feat to accomplish. The mxd will not recognize changes to scale, zooming, selections etc outside of the program accessing it, as all that is held in memory. You would have to make your edits using your GUI, save the mxd, then open ArcMap to see the changes.

As far as I know, the only feasible way to accomplish what you want to do will require ArcObjects.
0 Kudos
StacyRendall1
Frequent Contributor
I'm not sure what the overall specifications of your program are: if it needs to be distributed, the level of user, how often it will be used. From the amount of effort you have gone to so far, I'm guessing you need a pretty polished product.

This got me thinking: if you wanted to stick with Python to do this you could check out Quantum GIS (QGIS) - it's an open source viewer with simple editing and geoprocessing capabilities. It should easily be able to do what you have described so far...

It supports actual plugins, not just tools, written in Python. I have dabbled with it a little, and the structure is pretty straight forward. I think you can also integrate the plugin into the program a lot more than what you can in Arc, so you could still use program features while it's running, or use the GUI to force refreshes, etc.

The fact that you can stick with Python to do it would be handy, although I think the GUI is based around Qt, meaning you may have to translate from Tk to Qt - GUI programs don't often play together nicely.

Issues:

  1. It uses different files to Arc; so you would have to remake your maps in QGIS.

  2. Currently (this should change soon...) you would need all your data in .shp or .mdb files. ESRI only recently opened up the .gdb format and the open source drivers to actually use this haven't made their way to release yet...


It may be more effort than it's worth for you, but do let me know how you get on!
0 Kudos
PatrickJurgens
Deactivated User
The tool I am building will be used by 5 or 6 people in my office. It will be used intensely for about a month, and then they will not need it any more.
The expectations placed on me are low. We had a programmer who did this sort of thing in ArcObjects, but he quit. We weren't able to hire a replacement, so now I am trying to make something to at least fill the gap.
I know QGIS, but cannot use it at work because of constraints on what software can be installed on our workstations (hence I am using Python and Tkinter. They were already on my machine). Since I am not a 'developer' I don't get much choice in the tools available to me.
If I had complete control over my computer I would consider using QGIS or ArcObjects.

Thank you both for your suggestions.
0 Kudos
LoganPugh
Frequent Contributor
If you can install Python modules, comtypes would let you use ArcObjects in Python. This way you could access and modify objects in the running ArcMap application from outside the application boundary using AppROT.

See links:
http://gis.stackexchange.com/questions/80/how-do-i-access-arcobjects-from-python
http://gis.stackexchange.com/questions/5039/arcmap-arcobjects-drawing-graphics-onscreen-explanation-...
http://gis.stackexchange.com/questions/5017/python-comtypes-and-arcobjects-error-creating-approt-obj...
0 Kudos
PatrickJurgens
Deactivated User
lpugh01:
This is a very useful suggestion. I can ask for permission to add this module. I am assuming all end users of the end product will need to have this module as well (or I learn how to compile my script with PythonWin).
0 Kudos