Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

ArcGIS crashes on simple addin

$
0
0
Hi,

I'm starting to develop add-ins for a project. I have a very simple button that opens a new tab with Google Search results based on whatever footprint is selected at the time. Here's the code:

Code:

import arcpy
import pythonaddins
import webbrowser

mxd = arcpy.mapping.MapDocument('CURRENT')

layerList = arcpy.mapping.ListLayers(mxd)
tableList = arcpy.mapping.ListTableViews(mxd)
for layer in layerList:
    if "Footprints_Edit" in layer.name:
        footprints_fc = layer
    if "Parcels_Edit" in layer.name:
        parcels_fc = layer
    if "Address" in layer.name:
        address_fc = layer
for table in tableList:
    if "Assessing" in table.name:
        assessing_table = table
    if "Condos" in table.name:
        condo_table = table

class GoogleLookup(object):
    """Implementation for building_footprints_Addin_addin.GoogleLookup (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self, footprints_fc=footprints_fc):
        fields = ["BCITY","BADDRESS"]
        with arcpy.da.SearchCursor(footprints_fc,fields) as rows:
            for row in rows:
                city = row[0]
                address = row[1]
                url = '''http://www.google.com/#q=%22''' + address.replace(' ','+') + '''%22%2C+''' + city.replace(' ','+') + '''%2C+MI '''
                webbrowser.open_new_tab(url)

Executing the code works, but then ArcGIS crashes immediately thereafter. I've gotten this to work before as a menu item but I lost that code! Any ideas?

Also, maybe .DMP should be a valid extension for forum uploads.

Viewing all articles
Browse latest Browse all 2485

Trending Articles