With python-addin-wizard I created a combobox which enables the user to select a specific ID of features in multiple featureclasses of the Table Of Content and then it zooms to the selected feature. So far so easy. It's not really fast, but it works okay.
items in the TOC appear to flicker and the processing is delayed considereably. I searched a lot in the arcpy functionalty, but can't find a bit of code to solve this Problem (quasi unselect the feature in the TOC). The only thing related to my Problem, that I found is pythonaddins.GetSelectedTOCLayerOrDataFrame() > But I have no idea how to unselect the layer.
Here is the part of the code which makes the selection and zoom:
def onSelChange(self, selection): self.value = selection fcsites2 = [fc_site_pol, fc_site_punkt, fc_site_linie, fc_neg_pol, fc_neg_punkt, fc_neg_linie, fc_unter_pol, fc_unter_punkt, fc_unter_linie] for x in fcsites2: arcpy.SelectLayerByAttribute_management(x, "NEW_SELECTION", fields_site + "='" + selection + "'") d = arcpy.Describe(x) n = len(d.FIDset) if n > 0: break self.df.zoomToSelectedFeatures() self.df.scale = 5000
@artwork21 helped me start to solve my problem using the comtypes module. I have no much experience with integrating ArcObjects in Python. I reached to reference the TOC and the selected layer once. Then I can unselect the layer with the code below.But when I try a second unselect it doesn't work. It seems like the first selected layer is still known as selected like in a cache.
mU = GetModule(r"C:\Program Files (x86)\ArcGIS\Desktop10.2\com\esriArcMapUI.olb") mF = GetModule(r"C:\Program Files (x86)\ArcGIS\Desktop10.2\com\esriFramework.olb") app = CreateObject(mF.AppROT, interface=mF.IAppROT) pDoc = CType(app.Item(0).Document,mU.IMxDocument) pMap = pDoc.FocusMap ptoc = CType(pDoc.ContentsView(0),mU.IContentsView) pselLayer = pDoc.SelectedLayer if pselLayer != 0: print pselLayer.Name ptoc.RemoveFromSelectedItems(pselLayer) ptoc.Refresh