def onClick(self): self.mxd = arcpy.mapping.MapDocument('current') layers = arcpy.mapping.ListLayers(self.mxd) self.items = [] for layer in layers: if layer.name.lower() == "hydrantm": hydLayer = layer print hydLayer df = arcpy.mapping.ListDataFrames(self.mxd)[0] extent = str(df.extent) print extent dfAsFeature = arcpy.Polygon(arcpy.Array([df.extent.lowerLeft, df.extent.lowerRight, df.extent.upperRight, df.extent.upperLeft]), df.spatialReference) arcpy.SelectLayerByLocation_management(hydLayer, "INTERSECT", dfAsFeature, "", "NEW_SELECTION")
Solved! Go to Solution.
def onClick(self): self.mxd = arcpy.mapping.MapDocument('current') layers = arcpy.mapping.ListLayers(self.mxd) self.items = [] for layer in layers: if layer.name.lower() == "parks": hydLayer = layer print hydLayer df = arcpy.mapping.ListDataFrames(self.mxd)[0] extent = str(df.extent) print extent dfAsFeature = arcpy.Polygon(arcpy.Array([df.extent.lowerLeft, df.extent.lowerRight, df.extent.upperRight, df.extent.upperLeft]), df.spatialReference) arcpy.SelectLayerByLocation_management(hydLayer, "INTERSECT", dfAsFeature, "", "NEW_SELECTION") global labels labels = [] with arcpy.da.SearchCursor(hydLayer, ["NAME"]) as cursor: for row in cursor: labels.append(row[0]) del cursor, row
def onFocus(self, focused): self.items = labels
rows = arcpy.SearchCursor(hydLayer, "", "", "NAME") for row in rows: labels.append(row.NAME) del row, rows
def onClick(self): self.mxd = arcpy.mapping.MapDocument('current') layers = arcpy.mapping.ListLayers(self.mxd) self.items = [] for layer in layers: if layer.name.lower() == "parks": hydLayer = layer print hydLayer df = arcpy.mapping.ListDataFrames(self.mxd)[0] extent = str(df.extent) print extent dfAsFeature = arcpy.Polygon(arcpy.Array([df.extent.lowerLeft, df.extent.lowerRight, df.extent.upperRight, df.extent.upperLeft]), df.spatialReference) arcpy.SelectLayerByLocation_management(hydLayer, "INTERSECT", dfAsFeature, "", "NEW_SELECTION") global labels labels = [] with arcpy.da.SearchCursor(hydLayer, ["NAME"]) as cursor: for row in cursor: labels.append(row[0]) del cursor, row
def onFocus(self, focused): self.items = labels
rows = arcpy.SearchCursor(hydLayer, "", "", "NAME") for row in rows: labels.append(row.NAME) del row, rows