Script stopped working properly with upgrade of ArcGIS Pro

202
5
05-06-2021 06:54 AM
michael_vetter
Occasional Contributor

I created a Python script that calculates fields of newly added points. When I run the script in ArcGIS Pro 2.5 everything works correctly, but when I upgraded to version 2.7.3 of Pro, 3 of the fields no longer populate. I don't get any errors from the script. Thanks in advance for any help!

import arcpy

#Setup the user inputs
customerPointSelection = arcpy.GetParameterAsText(0)
customerPoint = arcpy.GetParameterAsText(1)
automatedCollection = arcpy.GetParameterAsText(2)

#Create a spatial join between customerPointSelection and automatedCollection
arcpy.SpatialJoin_analysis(customerPointSelection, automatedCollection, "in_memory/CustomerAutoJoin", "JOIN_ONE_TO_MANY","KEEP_COMMON","","WITHIN")
#Create a new join to the customerPoint
arcpy.AddJoin_management(customerPoint,"OBJECTID","in_memory/CustomerAutoJoin","TARGET_FID","KEEP_COMMON")
#Calculate the needed fields
arcpy.CalculateField_management(customerPoint,"SEC_NAME","!CustomerAutoJoin.SEC_NAME_1!","PYTHON3","","TEXT")
arcpy.CalculateField_management(customerPoint,"COLLECT_DAY","!CustomerAutoJoin.DAY!","PYTHON3","","TEXT")
arcpy.management.CalculateField(customerPoint,"QUAD","!CustomerAutoJoin.QUAD_1!","PYTHON3","","TEXT")
arcpy.CalculateField_management(customerPoint,"HELP_SECTION","!CustomerAutoJoin.HELP_SECTION_1!","PYTHON3","","SHORT")
#Remove the join and delete the in memory feature
arcpy.RemoveJoin_management(customerPoint)
arcpy.Delete_management("in_memory/CustomerAutoJoin")

 

0 Kudos
5 Replies
r3weber
New Contributor II
try management.CalculateField for all field calculations
 
not CalculateField_management
0 Kudos
DanPatterson
MVP Honored Contributor

from

Calculate Field (Data Management)—ArcGIS Pro | Documentation

You can examine the code and its location and you will see that both methods lead to the exact same function in the same file.  The "dot notation" is now preferred but the other is still usable.

 

from arcpy import CalculateField_management

from arcpy.management import CalculateField

# ---- use help on either one

Source:   
@gptooldoc('CalculateField_management', None)
def CalculateField(in_table=None, field=None, expression=None, expression_type=None, code_block=None, field_type=None, enforce_domains=None):
.... snip ....
File:      c:\arc_pro\resources\arcpy\arcpy\management.py
Type:      function

 

 


... sort of retired...
r3weber
New Contributor II
This example works for me using the latest base arcgis pro python environment...so that's all I got!  Good luck.
 
fieldName = r'SYS_TRANSFER_DATE'
expression = f"'{current_utc}' if !SYS_TRANSFER_DATE! is None else !SYS_TRANSFER_DATE!"
    
arcpy.CalculateField_management(workspace, fieldName, expression, "PYTHON3")
0 Kudos
michael_vetter
Occasional Contributor

Thank you @r3weber and @DanPatterson for suggesting using the dot notation. I changed the script to include the dot notation and was getting the same results. I looked at the results from the spatial join layer and the spatial join layer isn't getting all the attributes from the polygon layer, but I'm not exactly sure why some of the fields aren't getting populated even though the polygon layer has attributes for those fields.

0 Kudos
JeffK
by
Occasional Contributor III

I've had mixed results between using 'in_memory' and 'memory' with python 3 scripts.  Some work with using  'memory' and others work with using 'in_memory'. If you haven't already, try just 'memory' or writing to disk to see the results at each step.

I've also had mixed results with using dot notation while using pycharm. Ran as a script tool, it works but when I run it externally as a standalone script it throws errors.