<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: GetCount and Update Cursor not honoring selection in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/getcount-and-update-cursor-not-honoring-selection/m-p/1231387#M62213</link>
    <description>&lt;P&gt;I had an issue like this when running a Python tool. You would need to create a feature layer from your original feature class to make selections on, rather than the original feature class. That worked just fine for me, once I did that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edited for typos and clarity.&lt;/P&gt;</description>
    <pubDate>Mon, 14 Nov 2022 19:25:35 GMT</pubDate>
    <dc:creator>JamesWilcox1970</dc:creator>
    <dc:date>2022-11-14T19:25:35Z</dc:date>
    <item>
      <title>GetCount and Update Cursor not honoring selection</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/getcount-and-update-cursor-not-honoring-selection/m-p/1231318#M62196</link>
      <description>&lt;P&gt;I'm using arcpy, teaching myself so apologies for my code!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the update cursor to input the number of selected rows from a feature class into the score field of another using this code. It all seems to be working apart from the selection is not being honoured, I'm expecting to see a raw score of 1 and actually I'm getting 879.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# -*- coding: utf-8 -*-
"""
Generated by ArcGIS ModelBuilder on : 2022-11-14 10:26:09
"""
import arcpy

# Set environments
arcpy.env.workspace = r"c:\Users\CVSmith\OneDrive - Fauna &amp;amp; Flora International\Projects\ENI_HBRA\projects\ENI_HBRA_Scratch\HBRA_Scratch.gdb"

def Model1():  # Model1

    # To allow overwriting outputs change overwriteOutput option to True.
    arcpy.env.overwriteOutput = True

    arcpy.ImportToolbox(r"c:\program files\arcgis\pro\Resources\ArcToolbox\toolboxes\Data Management Tools.tbx")
    CulturalSites = r"c:\Users\CVSmith\OneDrive - Fauna &amp;amp; Flora International\Projects\ENI_HBRA\datasets\HBRA_data\whc_sites_2021_CulturalBuffer_MLW.shp"
    AU_Test = "AU_FR"
   
    # Process: Select Layer By Location (Select Layer By Location) (management)
    CulturalSites = arcpy.management.SelectLayerByLocation(CulturalSites, "INTERSECT", AU_Test, "", "NEW_SELECTION", "NOT_INVERT")

    # Add Fields for scoring
    arcpy.management.AddFields(AU_Test, [['F2_Raw', 'SHORT'], ['F2_Score','LONG']])

    # Count number of intersecting features for F2_Raw score using Update cursor and Get Count
    fields = ['F2_Raw']

    with arcpy.da.UpdateCursor(AU_Test,fields) as cursor:
        for row in cursor:
            row[0] = int(arcpy.GetCount_management(CulturalSites).getOutput(0))
            cursor.updateRow(row)

    del row
   
    # Process: Calculate Field (2) (Calculate Field) (management)
    arcpy.management.CalculateField(AU_Test, "F2_Score", "Score(!F2_Score!,!F2_Raw!)", "PYTHON3", """def Score(F2_Score,F2_Raw):
    if (F2_Raw &amp;gt; 0):
        return 5
    else:
        return 1""", "TEXT", "NO_ENFORCE_DOMAINS")
    
if __name__ == '__main__':
    # Global Environment settings
    with arcpy.EnvManager(scratchWorkspace=r"c:\Users\CVSmith\OneDrive - Fauna &amp;amp; Flora International\Projects\ENI_HBRA\projects\ENI_HBRA_Scratch\HBRA_Scratch.gdb", workspace=r"c:\Users\CVSmith\OneDrive - Fauna &amp;amp; Flora International\Projects\ENI_HBRA\projects\ENI_HBRA_Scratch\HBRA_Scratch.gdb"):
        Model1()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 17:12:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/getcount-and-update-cursor-not-honoring-selection/m-p/1231318#M62196</guid>
      <dc:creator>ChelseaVSmith</dc:creator>
      <dc:date>2022-11-14T17:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: GetCount and Update Cursor not honoring selection</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/getcount-and-update-cursor-not-honoring-selection/m-p/1231387#M62213</link>
      <description>&lt;P&gt;I had an issue like this when running a Python tool. You would need to create a feature layer from your original feature class to make selections on, rather than the original feature class. That worked just fine for me, once I did that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edited for typos and clarity.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 19:25:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/getcount-and-update-cursor-not-honoring-selection/m-p/1231387#M62213</guid>
      <dc:creator>JamesWilcox1970</dc:creator>
      <dc:date>2022-11-14T19:25:35Z</dc:date>
    </item>
  </channel>
</rss>

