AnsweredAssumed Answered

addin tool not selecting by location

Question asked by kevin.bell_slcgov on Apr 13, 2018
Latest reply on Apr 23, 2018 by kevin.bell_slcgov

I'm making a python addin select tool that allows the user to draw a rectangle and then select points within it to then do stuff.  For testing I'm only counting how many points are selected and writing to a log file, but it always returns 0... What am I doing wrong here?

 

def onRectangle(self, rectangle_geometry):
   ext = rectangle_geometry

   array = arcpy.Array()
   array.add(arcpy.Point(ext.XMin, ext.YMin))
   array.add(arcpy.Point(ext.XMin, ext.YMax))
   array.add(arcpy.Point(ext.XMax, ext.YMax))
   array.add(arcpy.Point(ext.XMax, ext.YMin))
   array.add(arcpy.Point(ext.XMin, ext.YMin))
   polygon = arcpy.Polygon(array)
   arcpy.CopyFeatures_management(polygon, "in_memory//Polygon_Extent")
   arcpy.MakeFeatureLayer_management("in_memory//Polygon_Extent", 'selectLyr')

   arcpy.MakeFeatureLayer_management('events', 'eventsLyr')

   arcpy.SelectLayerByLocation_management('eventsLyr', 'INTERSECT','selectLyr')
   n = arcpy.GetCount_management('eventsLyr')

   f = open(r'E:\ArcMap\BuildingServices\20180411_misassignedInspectors\addin\log.txt','a')
   f.write(str(n) + '\n')
   f.close()

   arcpy.Delete_management("in_memory//Polygon_Extent")
   arcpy.Delete_management('selectLyr')
   arcpy.Delete_management('eventsLyr')

Outcomes