I worked out a Python Add-In Combox, that combines different Fields from different Feature Class in one Drop-Down-List. The user can select one ID/Code in the Drop-Donw list and the active view zooms to the selection. So far it's not very fast, but it works. My problem is, that Arc Map crashes, when I use the Combobox and a Feature Layer is selected. This I can't fix. Did anybody has an idea?
Here is my code:
import sys, os, arcpy, zipfile, traceback, pythonaddins
from arcpy import mapping, env
class SiteComboBoxClass43(object):
"""Implementation for Site_Python_Addins_addin.combobox (ComboBox)"""
def __init__(self):
self.items = []
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWWWWW'
self.width = 'WWWWWWWWW'
def onFocus(self, focused):
if focused:
self.mxd = arcpy.mapping.MapDocument('current')
global items, site, akode, fc_biotop_pol, fc_biotop_poi, fc_biotop_li, fc_pro1_pol, fc_pro1_poi, fc_pro1_li
items = []
fields_site = "SITE_ID"
akode = "AKODE"
fc_biotop_pol = "Biotop (Polygon)"
fc_biotop_poi = "Biotop (Point)"
fc_biotop_li = "Biotop (Line)"
fc_pro1_pol = "Protection Area 1 (Polygon)"
fc_pro1_poi = "Protection Area 1 (Point)"
fc_pro1_li = "Protection Area 1 (Line)"
fcsites1 = [fc_biotop_pol, fc_biotop_poi, fc_biotop_li, fc_pro1_pol, fc_pro1_poi, fc_pro1_li]
fcakode1 = [fc_pro1_pol, fc_pro1_poi, fc_pro1_li]
for x in fcsites1:
for row in arcpy.da.SearchCursor(x,fields_site): items.append(row[0])
for x in fcakode1:
for row in arcpy.da.SearchCursor(x,akode): items.append(row[0])
self.items = sorted(items)
pass
def onSelChange(self, selection):
combobox.enabled = True
self.value = selection
self.mxd = arcpy.mapping.MapDocument('current')
self.df = arcpy.mapping.ListDataFrames(self.mxd)[0]
if len(selection) > 8:
fcsites2 = [fc_biotop_pol, fc_biotop_poi, fc_biotop_li, fc_pro1_pol, fc_pro1_poi, fc_pro1_li]
for x in fcsites2:
arcpy.SelectLayerByAttribute_management(x, "NEW_SELECTION", fields_site + "='" + selection + "'")
else:
fcakode2 = [fc_pro1_pol, fc_pro1_poi, fc_pro1_li]
for x in fcakode2:
arcpy.SelectLayerByAttribute_management(x, "NEW_SELECTION", akode + "='" + selection + "'")
self.df.zoomToSelectedFeatures()
self.df.scale = 15000
pass