I'm trying to add a tool to an add-in toobar to select features from an existing feature class and copy them across to another feature class. I need two tools, one for a point and one for a rectangle. Add-in tools only handle rectangles, so I'm trying to generate the point coordinate off the onMouseDown event and simply use the X and Y feedback I get. The problem is that I can't seem to pass these coordinates to anything usefull to extract the features. I've tried using Environment extents and then doing a simple CopyFeatures, but that's not working as it copies the entire fc and doesn't seem to honour the environment settings I set.
Can I pass coordinates to the Select by Location tool somehow or is there another way of passing coordinates to something to extract by that extent?
This is what I have now:
import arcpy import pythonaddins arcpy.overWriteOutput = True # Replace this with the SDE layer once it's available. global ELAtemplate, fc ELAtemplate = r'C:\Data\nsw_map_units.shp' fc = "" class DefineUnitsbyPoint(object): """Implementation for DefineUnitsbyPoint.tool (Tool)""" def __init__(self): self.enabled = True self.shape = "Rectangle" # Use onMouseDown to get initial extent of the rectangle. def onMouseDownMap(self, x, y, button, shift): # fc can be assigned from a combo box selection in another class global ELAtemplate, fc if fc == "": pythonaddins.MessageBox('Choose a layer to select from.', 'Choose a Layer', 0) else: mxd = arcpy.mapping.MapDocument("CURRENT") pointGeom = arcpy.PointGeometry(arcpy.Point(x,y), mxd.activeDataFrame.spatialReference) arcpy.SelectLayerByLocation_management(ELAtemplate, "INTERSECT", pointGeom, "", "ADD_TO_SELECTION") arcpy.CopyFeatures(ELAtemplate, fc)