I cannot get the arcpy.env.extent working for Select Layer By Attribute GP tool. I can verify that I get various values for coordinates when I have panned to various areas on the map. Copy Features GP tool does export only those feature that are located within the current visible map extent. According to the Select Layer By Attribute GP tool documentation:
If an Extent environment is specified, or if a definition query is present on the Input Layer or Table View, only the features or rows within the extent or matching the definition query may be selected.
Has anyone succeeded selecting features that are within the extent only? When I run the code below, regardless of the map extent, all features that fulfill the query requirements are selected.
This is the code I execute in the Python window in ArcMap.
fc = "Water distribution network fittings" #layer name in the TOC field = "ObjectId" mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd,"Layers") print df.extent.XMin, df.extent.YMin, df.extent.XMax,df.extent.YMax arcpy.env.extent = df.extent #also tried arcpy.Extent(XMin, YMin, XMax, YMax) arcpy.CopyFeatures_management(fc, "in_memory\outputFeatures") #adds new layer correctly arcpy.SelectLayerByAttribute_management(in_layer_or_view=fc,selection_type="NEW_SELECTION",where_clause = """ObjectId > 160""")