laptop and a wrench

Bug

When using arcpy.SelectLayerByAttribute() in ArcGIS Pro 2.6.X, all records are returned instead of just the selected records inside both the IDE and the ArcGIS Pro user interface.

Zuletzt veröffentlicht: November 13, 2020 ArcGIS Pro
Bug-ID-Nummer BUG-000135234
EingereichtNovember 6, 2020
Zuletzt geändertOctober 7, 2024
Gilt fürArcGIS Pro
Gefunden in Version2.6.1
BetriebssystemWindows OS
Betriebssystemversion10.0 64 Bit
StatusNon-Reproducible

Zusätzliche Informationen

The correct count is returned by the arcpy.SelectLayerByAttribute() function. This is verified by printing the derived output parameter in the second position of the returned object, which is the count of selected features, refer to https://pro.arcgis.com/en/pro-app/tool-reference/data-management/select-layer-by-attribute.htm or ensuring get count is called on the correct layer object: a = arcpy.management.SelectLayerByAttribute(, "NEW_SELECTION", "", None) print(arcpy.management.GetCount(a.getOutput(0).name)) The issue is related to the ambiguity of layer and feature class names.

Workaround

Options:

  1. Use arcpy.management.MakeFeatureLayer first before arcpy.management.SelectLayerByAttribute.
  2. Connect to the feature through the path to the project.
  3. Use the python window or Notebook within the ArcGIS Pro 2.5.1 User Interface

Example for option 1:

import arcpy

arcpy.management.MakeFeatureLayer(r"C:\Users\Desktop\Shapefile\Arcpy\esri\Testing.gdb\Polygons","Testl")

arcpy.management.SelectLayerByAttribute("Testl", "SUBSET_SELECTION", "LANDAREACODE = '021'", None)

print(arcpy.management.GetCount("Testl"))

Example for option 2:

import arcpy

import os

aprx = arcpy.mp.ArcGISProject(r"C:\ArcPy\ArcPy.aprx")

maps = aprx.listMaps()[0]

Polygon = maps.listLayers()[0]

print(Polygon)

arcpy.management.SelectLayerByAttribute(Polygon, "SUBSET_SELECTION", "LANDAREACODE = '021'", None)

print(arcpy.management.GetCount(Polygon))

Example for option 3:

import arcpy

arcpy.env.workspace = r"C:\Users\Desktop\Shapefile\Arcpy\esri\Testing.gdb"

a=arcpy.management.SelectLayerByAttribute("Polygons", "SUBSET_SELECTION", "LANDAREACODE = '021'", None)

print(arcpy.management.GetCount(a))

Schritte zur Reproduzierung

Bug-ID: BUG-000135234

Software:

  • ArcGIS Pro

Benachrichtigung erhalten, wenn sich der Status eines Bugs ändert

Esri Support App herunterladen

Weitere Informationen zu diesem Thema erkunden

Unterstützung durch ArcGIS-Experten anfordern

An den technischen Support wenden

Esri Support App herunterladen

Zu Download-Optionen wechseln