laptop and a wrench

Error

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.

Última publicación: November 13, 2020 ArcGIS Pro
Número de ID del error BUG-000135234
EnviadoNovember 6, 2020
Última modificaciónOctober 7, 2024
Relacionado conArcGIS Pro
Versión encontrada2.6.1
Sistema operativoWindows OS
Versión de sistema operativo10.0 64 Bit
EstadoNon-Reproducible

Información adicional

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.

Solución alternativa

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))

Pasos para reproducir

ID del error: BUG-000135234

Software:

  • ArcGIS Pro

Recibir notificaciones cuando cambie el estado de un error

Descargar la aplicación de soporte de Esri

Descubrir más sobre este tema

Obtener ayuda de expertos en ArcGIS

Contactar con el soporte técnico

Descargar la aplicación de soporte de Esri

Ir a opciones de descarga