<?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 using if then statement to check for empty out from find identical tool in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-if-then-statement-to-check-for-empty-out/m-p/1619772#M74308</link>
    <description>&lt;P&gt;All,&lt;/P&gt;&lt;P&gt;In arc pro I am developing a script to check for duplicates in a field for several layers. I have gotten the check to run in the loop with no issues. After the find identical tool runs i want to use a if then statement to check if the out put is blank and if it is not join the tables. How do i do this? It is failing at line 17. My code is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;F=("feature1","feature2","feature3","feature14")
b =0 

for e in F:
    a=F[b]
    s=str(a).replace(" ", "_")
    o= "C:\\path\\way\\ArcGIS\\Projects\\edit_map6\\edit_map6.gdb\\" +s+"_findidencal"
    arcpy.management.FindIdentical(
    in_dataset= a,
    out_dataset=o,
    fields="FACILITYID",
    xy_tolerance=None,
    z_tolerance=0,
    output_record_option="ONLY_DUPLICATES"

    )
    if o is not empty: 
        arcpy.management.AddJoin(
            in_layer_or_view=a,
            in_field="OBJECTID",
            join_table=o,
            join_field="IN_FID",
            join_type="KEEP_ALL",
            index_join_fields="NO_INDEX_JOIN_FIELDS",
            rebuild_index="NO_REBUILD_INDEX",
            join_operation="JOIN_ONE_TO_FIRST"
        )
    #print result
    
    b=b+1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Laura&lt;/P&gt;</description>
    <pubDate>Fri, 30 May 2025 20:29:03 GMT</pubDate>
    <dc:creator>Laura_m_Conner</dc:creator>
    <dc:date>2025-05-30T20:29:03Z</dc:date>
    <item>
      <title>using if then statement to check for empty out from find identical tool</title>
      <link>https://community.esri.com/t5/python-questions/using-if-then-statement-to-check-for-empty-out/m-p/1619772#M74308</link>
      <description>&lt;P&gt;All,&lt;/P&gt;&lt;P&gt;In arc pro I am developing a script to check for duplicates in a field for several layers. I have gotten the check to run in the loop with no issues. After the find identical tool runs i want to use a if then statement to check if the out put is blank and if it is not join the tables. How do i do this? It is failing at line 17. My code is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;F=("feature1","feature2","feature3","feature14")
b =0 

for e in F:
    a=F[b]
    s=str(a).replace(" ", "_")
    o= "C:\\path\\way\\ArcGIS\\Projects\\edit_map6\\edit_map6.gdb\\" +s+"_findidencal"
    arcpy.management.FindIdentical(
    in_dataset= a,
    out_dataset=o,
    fields="FACILITYID",
    xy_tolerance=None,
    z_tolerance=0,
    output_record_option="ONLY_DUPLICATES"

    )
    if o is not empty: 
        arcpy.management.AddJoin(
            in_layer_or_view=a,
            in_field="OBJECTID",
            join_table=o,
            join_field="IN_FID",
            join_type="KEEP_ALL",
            index_join_fields="NO_INDEX_JOIN_FIELDS",
            rebuild_index="NO_REBUILD_INDEX",
            join_operation="JOIN_ONE_TO_FIRST"
        )
    #print result
    
    b=b+1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Laura&lt;/P&gt;</description>
      <pubDate>Fri, 30 May 2025 20:29:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-if-then-statement-to-check-for-empty-out/m-p/1619772#M74308</guid>
      <dc:creator>Laura_m_Conner</dc:creator>
      <dc:date>2025-05-30T20:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: using if then statement to check for empty out from find identical tool</title>
      <link>https://community.esri.com/t5/python-questions/using-if-then-statement-to-check-for-empty-out/m-p/1619780#M74309</link>
      <description>&lt;P&gt;GetCount ? should work&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/get-count.htm" target="_blank"&gt;Get Count (Data Management)—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 May 2025 20:36:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-if-then-statement-to-check-for-empty-out/m-p/1619780#M74309</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2025-05-30T20:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: using if then statement to check for empty out from find identical tool</title>
      <link>https://community.esri.com/t5/python-questions/using-if-then-statement-to-check-for-empty-out/m-p/1619786#M74310</link>
      <description>&lt;P&gt;&amp;nbsp;I would use GetCount_management()&amp;nbsp; .&lt;/P&gt;&lt;P&gt;Maybe something like this...&lt;/P&gt;&lt;LI-CODE lang="c"&gt;# Get count of duplicates
    count_result = arcpy.management.GetCount(o)
    count = int(count_result[0])
    print(f"\nFeature class: {a}")
    print(f"Number of duplicates found: {count}")

    if count &amp;gt; 0:
        # Print duplicate rows
        print("Duplicate entries:")
        with arcpy.da.SearchCursor(o, ["FID", "FEAT_SEQ"]) as cursor:
            for row in cursor:
                print(f"  FID: {row[0]}, FEAT_SEQ: {row[1]}")

        # Optional: Join duplicates to original layer
        arcpy.management.AddJoin(
            in_layer_or_view=a,
            in_field="OBJECTID",
            join_table=o,
            join_field="IN_FID",
            join_type="KEEP_ALL",
            index_join_fields="NO_INDEX_JOIN_FIELDS",
            rebuild_index="NO_REBUILD_INDEX",
            join_operation="JOIN_ONE_TO_FIRST"
        )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;LI-CODE lang="c"&gt;if int(arcpy.GetCount_management(o).getOutput(0)) &amp;gt; 0:
        arcpy.management.AddJoin(
            in_layer_or_view=a,
            in_field="OBJECTID",
            join_table=o,
            join_field="IN_FID",
            join_type="KEEP_ALL",
            index_join_fields="NO_INDEX_JOIN_FIELDS",
            rebuild_index="NO_REBUILD_INDEX",
            join_operation="JOIN_ONE_TO_FIRST"
        )
        print(f"Joined duplicates from {o} to {a}")
    else:
        print(f"No duplicates found in {a}")&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 30 May 2025 20:52:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-if-then-statement-to-check-for-empty-out/m-p/1619786#M74310</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2025-05-30T20:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: using if then statement to check for empty out from find identical tool</title>
      <link>https://community.esri.com/t5/python-questions/using-if-then-statement-to-check-for-empty-out/m-p/1621570#M74327</link>
      <description>&lt;P&gt;The GetCount function is actually incredibly slow compared to Cursors:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def cursor_len():
    return sum(1 for _ in SearchCursor(r'&amp;lt;Feature\Path&amp;gt;', ['OID@']))

def get_count():
    return int(GetCount(r'&amp;lt;Feature\Path&amp;gt;').getOutput(0))

&amp;gt;&amp;gt;&amp;gt; %timeit cursor_len()
519 µs ± 7.09 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

&amp;gt;&amp;gt;&amp;gt; %timeit get_count()
156 ms ± 2.32 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)&lt;/LI-CODE&gt;&lt;P&gt;You can parameterize that function and use it place of your `empty` option:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def feature_count(feature: str|arcpy._mp.Layer):
    return sum(1 for _ in arcpy.da.SearchCursor(feature, ['OID@']))

...

if feature_count(o) &amp;gt; 0:
    ...&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 06 Jun 2025 16:25:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-if-then-statement-to-check-for-empty-out/m-p/1621570#M74327</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2025-06-06T16:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: using if then statement to check for empty out from find identical tool</title>
      <link>https://community.esri.com/t5/python-questions/using-if-then-statement-to-check-for-empty-out/m-p/1621606#M74328</link>
      <description>&lt;P&gt;Thanks the get count worked.&amp;nbsp; here is my final code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;F=("Sanitary Sewer Manholes","Water Network Structures","Water Fittings","Water System Valves","Water Service Connections","Water Hydrants","Sewer Gravity Mains","Sewer Pressurized Mains","Storm Drain Pipes", "Water Lateral Lines", "Water Mains")
b =0 

for e in F:
    a=F[b]
    s=str(a).replace(" ", "_")
    o= "C:\\Users\\lconner\\Documents\\ArcGIS\\Projects\\edit_map6\\edit_map6.gdb\\" +s+"_findidencal"+str(7)
    arcpy.management.FindIdentical(
    in_dataset= a,
    out_dataset=o,
    fields="FACILITYID",
    xy_tolerance=None,
    z_tolerance=0,
    output_record_option="ONLY_DUPLICATES")

    count_result = arcpy.management.GetCount(o)
    count = int(count_result[0])
    
    
    if count &amp;gt; 0:
        print("Duplicate entries in"+str (a) )
        print(f"Number of duplicates found: {count}")
        arcpy.management.AddJoin(
            in_layer_or_view=a,
            in_field="OBJECTID",
            join_table=o,
            join_field="IN_FID",
            join_type="KEEP_ALL",
            index_join_fields="NO_INDEX_JOIN_FIELDS",
            rebuild_index="NO_REBUILD_INDEX",
            join_operation="JOIN_ONE_TO_FIRST"
        )


        arcpy.management.SelectLayerByAttribute(
            in_layer_or_view= a,
            selection_type="NEW_SELECTION",
            where_clause="IN_FID IS NOT NULL",
            invert_where_clause=None
            )
    

    else:
        print("no Duplicate in " + str(a) )

    
    b=b+1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jun 2025 17:58:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-if-then-statement-to-check-for-empty-out/m-p/1621606#M74328</guid>
      <dc:creator>Laura_m_Conner</dc:creator>
      <dc:date>2025-06-06T17:58:58Z</dc:date>
    </item>
  </channel>
</rss>

