Select to view content in your preferred language

add-in combobox: finding selected row in different featurelayers

3781
2
11-03-2015 11:33 PM
FranziskaBeau
Deactivated User

I am very new at Python add in and I'm developing a search-Combobox with values from different feature layers from my Dataframe.What the Combobox does is, that

the User can select an ID or activitycode (acode), which are in different featurelayers and the active view zooms to

the object (biotop or Protection Area). The Combobox works, but it's very slow, because it looks up in every layer. What I want to do - but don't get - is that in the onSelChange definition

some loop is done. The problem is, that I can't get the featurelayers and I don't know how to define the selection for doing some if-elif-else-loop. Thank you very mucho for help !!

Here my code:

class SiteComboBoxClass4(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 = []
  site = "SITE_ID"
  acode = "ACODE"
  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)"
  Cursor_1 = arcpy.da.SearchCursor(fc_biotop_pol,site)
  Cursor_2 = arcpy.da.SearchCursor(fc_biotop_poi,site)
  Cursor_3 = arcpy.da.SearchCursor(fc_biotop_li,site)
  Cursor_4 = arcpy.da.SearchCursor(fc_pro1_pol,site)
  Cursor_5 = arcpy.da.SearchCursor(fc_pro1_poi,site)
  Cursor_6 = arcpy.da.SearchCursor(fc_pro1_li,site)
  Cursor_7 = arcpy.da.SearchCursor(fc_pro1_pol,acode)
  Cursor_8 = arcpy.da.SearchCursor(fc_pro1_poi,acode)
  Cursor_9 = arcpy.da.SearchCursor(fc_pro1_li,acode)
  for row in Cursor_1: items.append(row[0])
  for row in Cursor_2: items.append(row[0])
  for row in Cursor_3: items.append(row[0])
  for row in Cursor_4: items.append(row[0])
  for row in Cursor_5: items.append(row[0])
  for row in Cursor_6: items.append(row[0])
  for row in Cursor_7: items.append(row[0])
  for row in Cursor_8: items.append(row[0])
  for row in Cursor_9: 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]  

 arcpy.SelectLayerByAttribute_management(fc_biotop_poi, "NEW_SELECTION", site + "='" + selection + "'")
 self.df.zoomToSelectedFeatures()
 arcpy.SelectLayerByAttribute_management(fc_biotop_li, "NEW_SELECTION", site + "='" + selection + "'")
 self.df.zoomToSelectedFeatures()
 #arcpy.RefreshActiveView()
arcpy.SelectLayerByAttribute_management(fc_biotop_pol, "NEW_SELECTION", site + "='" + selection + "'")
 self.df.zoomToSelectedFeatures()
 arcpy.SelectLayerByAttribute_management(fc_pro1_poi, "NEW_SELECTION", site + "='" + selection + "'")
 self.df.zoomToSelectedFeatures()
 arcpy.SelectLayerByAttribute_management(fc_pro1_li, "NEW_SELECTION", site + "='" + selection + "'")
self.df.zoomToSelectedFeatures()
 arcpy.SelectLayerByAttribute_management(fc_pro1_pol, "NEW_SELECTION", site + "='" + selection + "'")
 self.df.zoomToSelectedFeatures()
 arcpy.SelectLayerByAttribute_management(fc_pro1_poi, "NEW_SELECTION", acode + "='" + selection + "'")
 self.df.zoomToSelectedFeatures()
 arcpy.SelectLayerByAttribute_management(fc_pro1_li, "NEW_SELECTION", acode + "='" + selection + "'")
 self.df.zoomToSelectedFeatures()
 arcpy.SelectLayerByAttribute_management(fc_pro1_pol, "NEW_SELECTION", acode + "='" + selection + "'")
 self.df.zoomToSelectedFeatures()
 pass
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
2 Replies
WesMiller
Deactivated User

Would you please repost your code using Dan Patterson's Blog  suggestions it's hard to read when it's not properly formatted. Could you also give a clear description of what you are trying to accomplish. It would help me if you write pseudo code laying out step by step 

0 Kudos
FranziskaBeau
Deactivated User

Hello ,

thank you for replying my question. I made a Combobox with the python add-in-wizard.
It works very simple: (1) The user selects the site-id or activity -code of a Biotop or protected  area. (2) The active view zooms to the selected feature.

The task is, that the user don't need to know, if the ID depends to an biotop or protected area nor if it is a point-, line- or polygonfeature. The Combobox works, but the zoom-to-part is very slow, because it looks in every featurelayer, if the selection is in it. My Problem is, that I can't define the selection for using it in some loop. I hope my question now get's a bit clearer.

0 Kudos