ArcPy Combobox How to leave a if-loop, when selection is found
I developed a Combox which:
- combines values from different featurelayers
- the User can select an ID or activitycode (acode)
- the active view zooms to the object (biotop or Protected Area)
The Combobox works very slow. Populating the Combobox with the values goes quite quick. But the zoom to the selected features is very slow. The problem is, that the if-loop, iterates through all featureclasses. I don't know how to leave the if-loop, when the selected feature is found. Currently it loops throgh the end of all tables of the listed featureclasses no matter if the selection already is found.
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)"
# build lists and populate the Combobox with sorted values
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]
# looking for the selected ID or code in the attributetable
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 + "'")
# zoom to Selection
self.df.zoomToSelectedFeatures()
self.df.scale = 15000
pass
for x in fcsites2: d = arcpy.Describe(x) n = len(d.FIDset) if n>0:break arcpy.SelectLayerByAttribute_management(x, "NEW_SELECTION", fields_site + "='" + selection + "'")