Hi, I have a model that works with a couple of AGOL hosted feature layers to summarize the number of points within polygons, and then perform an add join on the result in order to field calculate those numbers into a field within the polygon layer. The model works as expected, but exporting to a Python script and running the script doesn't seem to work. I am actually running the script using Windows Task Scheduler, and have had success with this method with other python scripts exported from ModelBuilder.
I'm wondering if somebody here could take a look at the script I'm trying to use and let me know if there is anything obvious that could be done to make it work? Thanks in advance for any assistance!
# -*- coding: utf-8 -*-
"""
Generated by ArcGIS ModelBuilder on : 2022-07-07 11:07:30
"""
import arcpy
def TrapperArea_SiteCounts(): # TrapperArea_SiteCounts
# To allow overwriting outputs change overwriteOutput option to True.
arcpy.env.overwriteOutput = True
arcpy.ImportToolbox(r"c:\program files\arcgis\pro\Resources\ArcToolbox\toolboxes\Analysis Tools.tbx.tbx")
L0AM_Trapper_Areas_Current = "https://services1.arcgis.com/cgAtrI0lk5jKC8Wy/arcgis/rest/services/AM_TrapperAreas_Ongoing/FeatureServer/0"
L0AM_Trap_Sites_Current = "https://services1.arcgis.com/cgAtrI0lk5jKC8Wy/arcgis/rest/services/AM_Survey_ActiveSites_VL/FeatureServer/0"
L0AM_Trapper_Areas_Current_2_ = "https://services1.arcgis.com/cgAtrI0lk5jKC8Wy/arcgis/rest/services/AM_TrapperAreas_Ongoing/FeatureServer/0"
# Process: Summarize Within (Summarize Within) (analysis)
c0_SummarizeWithin = "C:\\Users\\bcarman.SSV\\Washington State Executive Branch Agencies\\WSDA-PP - LID - General\\Automations\\Automation Scripts\\Apple Maggot\\AM Automation Models\\AM Automation Models\\Default.gdb\\c0_SummarizeWithin"
Output_Grouped_Table = ""
arcpy.analysis.SummarizeWithin(in_polygons=L0AM_Trapper_Areas_Current, in_sum_features=L0AM_Trap_Sites_Current, out_feature_class=c0_SummarizeWithin, keep_all_polygons="KEEP_ALL", sum_fields=[], sum_shape="ADD_SHAPE_SUM", shape_unit="", group_field="", add_min_maj="NO_MIN_MAJ", add_group_percent="NO_PERCENT", out_group_table=Output_Grouped_Table)
# Process: Add Join (Add Join) (management)
Updated_Input_Layer_or_Table_View = arcpy.management.AddJoin(in_layer_or_view=L0AM_Trapper_Areas_Current_2_, in_field="area_name", join_table=c0_SummarizeWithin, join_field="area_name", join_type="KEEP_ALL", index_join_fields="NO_INDEX_JOIN_FIELDS")[0]
# Process: Calculate Field (Calculate Field) (management)
L0AM_Trapper_Areas_Current_ = arcpy.management.CalculateField(in_table=Updated_Input_Layer_or_Table_View, field="L0AM_Trapper_Areas__Current.active_trap_count", expression="$feature['c0_SummarizeWithin.Point_Count']", expression_type="ARCADE", code_block="", field_type="TEXT", enforce_domains="NO_ENFORCE_DOMAINS")[0]
if __name__ == '__main__':
# Global Environment settings
with arcpy.EnvManager(scratchWorkspace=r"C:\Users\bcarman.SSV\Washington State Executive Branch Agencies\WSDA-PP - LID - General\Automations\Automation Scripts\Apple Maggot\AM Automation Models\AM Automation Models\Default.gdb", workspace=r"C:\Users\bcarman.SSV\Washington State Executive Branch Agencies\WSDA-PP - LID - General\Automations\Automation Scripts\Apple Maggot\AM Automation Models\AM Automation Models\Default.gdb"):
TrapperArea_SiteCounts()