Tell me more ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I created an ArcMap Python add-in using ArcGIS 10.1 to open a webpage after the map is clicked. It opens the page but then ArcGIS crashes.

import arcpy
import pythonaddins
import webbrowser
class ToolClass2(object):
    """Implementation for TEST_addin.tool (Tool)"""
    def __init__(self):
        self.enabled = True
        self.cursor=3
    def onMouseDownMap(self, x, y, button, shift):

    mxd=arcpy.mapping.MapDocument("current")
    df = arcpy.mapping.ListDataFrames(mxd)[0]
    pt=arcpy.PointGeometry(arcpy.Point(x,y))
    pythonaddins.MessageBox("Long" + " " + str(x) + '\n'+ "Lat"+ " " + str(y), 'Coordinates', 0)
    path = 'http://pol.pictometry.com/en-us/php/default.php?lat=' +str(x) +'&lon=' + str(y)+'&v=p&o=n&type=or&level=n'
    webbrowser.open(path)
    pass
share|improve this question
1  
Your indentation looks astray (mxd at same level as def) - perhaps fix it in Question or code, whichever applies. When you say Arc crashes do you mean it bails with a Serious Application Error or something else? – PolyGeo Feb 1 at 8:04
The above threaded method works fine for me, but I have to wait some 20 seconds before the browser actually opens which to most users is a crash! Is this speed correct? – Tony Collins Feb 4 at 17:39
@TonyCollins, The browser opens within a few seconds on the computers I have tried. I am not sure what is going on in your situation. How long does it take to normally open a web browser? – blah238 Feb 4 at 17:51

2 Answers

@BMac's code also crashes my ArcMap 10.1 SP1 installation.

This code works properly however:

import arcpy
import pythonaddins
import webbrowser
from threading import Thread

def OpenBrowserURL():
    url = 'http://www.google.com'
    webbrowser.open(url,new=2)

class OpenWebBrowserButtonClass(object):
    """Implementation for WebBrowserAddIn.openWebBrowserButton (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        t = Thread(target=OpenBrowserURL)
        t.start()
        t.join()

I call the same function from a new thread. Python add-in classes probably run on the UI thread by default and maybe there is some race condition or other issue causing ArcMap to crash, but if called from another thread it works.

Somewhat related: Crashing ArcGIS 10.1 Add-ins Using Multiprocessing

share|improve this answer

I opened the ArcMap python window and was able to run the following code successfully:

import webbrowser
url = 'http://www.google.com'
webbrowser.open(url,new=2)

However, I end up with the same issue when running as a python add-in. Closes/crashes ArcMap and opens the browser. Could be a bug in the add-in module or we need to rename our button to "Open browser and crash ArcMap". Sounds like you might need to call ESRI support to report a possible bug.

Sample Python add-in that crashes ArcMap:

import arcpy
import pythonaddins
import webbrowser

def OpenBrowserURL():
    url = 'http://www.google.com'
    webbrowser.open(url,new=2)

class OpenMetadata(object):
    """Implementation for TestAddins_addin.button1 (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        OpenBrowserURL()
share|improve this answer
Odd thing...occured – Kyle Feb 2 at 1:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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