Hi all,
I'm working on a script that uses the 'memory' workspace as layers are being processed, and I've hit an issue when I try to execute a field calculation between joined layers. I have included a script below that demonstrates the differences between workflows - the calculation will work fine if I create the feature layers from layers on disk, but will fail if the feature layers are created from layers in the memory workspace - testtype "fromdisk" works but testtype "frommemory" does not.
import arcpy
inLine = r"D:\TEMP\Output_20200520080600.gdb\LINE00240"
inPoint = r"D:\TEMP\Output_20200520080600.gdb\StructureJoin"
testtype = "fromdisk"
if testtype == "fromdisk":
print("Running disk workflow")
arcpy.MakeFeatureLayer_management(inLine, "LineFeature")
arcpy.MakeFeatureLayer_management(inPoint, "StructureFeature")
arcpy.AddJoin_management("LineFeature", "OBJECTID", "StructureFeature", "ORIG_FID", "KEEP_COMMON")
in_field = "Field_Name"
expression = '!StructureJoin.STRUCTURE_GUID!'
arcpy.CalculateField_management("LineFeature", in_field, expression, "PYTHON3")
elif testtype == "frommemory":
print("Running memory workflow")
arcpy.CopyFeatures_management(inLine, r"memory\Lines")
arcpy.CopyFeatures_management(inPoint, r"memory\Structures")
arcpy.MakeFeatureLayer_management(r"memory\Lines", "LineFeature")
arcpy.MakeFeatureLayer_management(r"memory\Structures", "StructureFeature")
arcpy.AddJoin_management("LineFeature", "OBJECTID", "StructureFeature", "ORIG_FID", "KEEP_COMMON")
in_field = "Field_Name"
expression = '!Structures.STRUCTURE_GUID!'
arcpy.CalculateField_management("LineFeature", in_field, expression, "PYTHON3")
The resulting error is:
Running memory workflow
Traceback (most recent call last):
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 4527, in CalculateField
retval = convertArcObjectToPythonObject(gp.CalculateField_management(*gp_fixargs((in_table, field, expression, expression_type, code_block, field_type), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 511, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds.
Failed to execute (CalculateField).
Do I need to do something different when using the memory workspace?