POST
|
Hello, finally I found a solution. You have to install the comtypes modul to integrate ArcObjects methods and with this you can unselect the layer: 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)
ptoc = CType(pDoc.ContentsView(0),mU.IContentsView)
ptoc.RemoveFromSelectedItems(pDoc.SelectedLayer)
ptoc.RemoveFromSelectedItems(pDoc.FocusMap) #deselects the dataframe name as well, if it's necessary like in my case
ptoc.Refresh
... View more
12-22-2016
03:27 AM
|
0
|
0
|
227
|
POST
|
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)"
# 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
... View more
04-04-2016
02:59 AM
|
0
|
1
|
3063
|
POST
|
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.
... View more
11-06-2015
06:30 AM
|
0
|
0
|
262
|
POST
|
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
... View more
11-03-2015
11:33 PM
|
0
|
2
|
3666
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|