ArcGIS Pro 2.5
I have made a manual selection of 38 polygons (of 240,000). In the python window of my project, I run a search cursor that looks like this:
with arcpy.da.SearchCursor(ng,'USNG')as cursor:
for row in cursor:
print(row)
And it prints the row until the cows come home. I found this post from last year: Why is Search Cursor not honoring layer Selection? but it's about selections being made outside of Pro. I just ran GetCount () and it returns all the records. What the heck is going on?
Where is ng being defined?
did you set your workspace just to be sure
Get Count—Data Management toolbox | Documentation
and it is a layer or table view?
If the input is a layer or table view containing a selected set of records, only the selected records will be counted.
ng is defined earlier as
r'Drive:\path\to\a\featureclass\named\NationalGrid'
And that my friends is the root of the problem. I insert the variable name, so it's looking at whats out there on disc, not the feature layer ArcGIS Pro has selected in the project. Same holds true for Get Count. When I let arcgis pro add the feature class or table name from the toc all is well. Although when I type in arcpy.getcount, it auto completes it the slightly different syntax of:
arcpy.management.GetCount('WesternTiles')
<Result '2'>
in this case I'm inserting the suggested table (view) name of WesternTiles, which I have two records selected.
Thanks-
And that is knowledge wrap for today folks...
Yep! My problem (at least on of them) is I spend more time in Spyder than than I do in Pro and have variables on the brain...