问题
I have written a Python Add-In for ArcGIS program ArcMap that uses the wxPython package to generate a wx.Frame window with multiple controls, including an Exit button that closes the window.
The Add-in works as intended the first time I run it, and I can close the wx.Frame window using the button without any errors. However, after a variable number of times running the Add-in, I get a fatal error on running the Add-In again. (Sometimes it fails the second time I run it. Sometimes I can run it multiple times before it fails.) The error window asks to send the report to ESRI, but unfortunately, the only output that ArcMap generates in this case is a .DMP file, which I assume is simply a memory dump. I don't know how to interpret it.
The Python script that is wrapped in the Add-In works fine from the Python command line in ArcMap (with suitable modifications), but running it from a button on an ArcMap user toolbar is more convenient.
Is there any way to generate a trace of what exactly was happening when it encountered the fatal error? There is no error message sent to the Python command line window when it fails.
回答1:
I was able to find an answer to this problem from a link in a posting on the ESRI GeoNet Community forum:
https://community.esri.com/thread/99532
(You need to logon to a free account on the forum to read the postings.) The original link was to a presentation by Mark Cederholm at the ESRI Developer summit 2010. The link in the forum post was obsolete, but I found another link to it:
https://www.esri.com/videos/watch?videoid=1229&isLegacy=true
that worked. The presentation shows how to build an ArcMap Extension which contains a toolbar and a button that loads when ArcMap starts. Instead of using wx.Close() or wx.Destroy to close the windows, it simply hides them using wx.Show(False). This approach allows using wxPython GUI interfaces on dialog boxes that can be opened, closed, and reopened repeatedly without crashing ArcMap.
I thought that this would be useful for other people using Python to build Add-Ins for ArcMap that make use of wxPython. Next, I will be converting another ArcMap Add-In that I currently use that was written in VB.NET in Visual Studio to Python using wxPython to build the GUI interface.
来源:https://stackoverflow.com/questions/49887825/repeated-calls-to-arcmap-python-add-in-with-wxpython-fail-after-one-successful-c