I successfully created python steps in Notebook, but when I converted to python script that I run from my toolbox it fails.
After joining a table to a feature class, the calculate field fails saying that I have an invalid field (ERROR 000530).
import arcpy
param1 = r"\\mynetworkpath\ResearchAndMaterialsCenter.gdb"
arcpy.management.MakeTableView(
in_table=param1 + r"\PavedShoulder_GenerateNearTable_SameRouteDirection",
out_view="PavedShoulder_GenerateNearTable_SameRouteDirection_View",
where_clause="NEAR_DIST <> 0",
workspace=None,
field_info="OBJECTID OBJECTID VISIBLE NONE;IN_FID IN_FID VISIBLE NONE;NEAR_FID NEAR_FID VISIBLE NONE;NEAR_DIST NEAR_DIST VISIBLE NONE;NEAR_RANK NEAR_RANK VISIBLE NONE;FROM_X FROM_X VISIBLE NONE;FROM_Y FROM_Y VISIBLE NONE;NEAR_X NEAR_X VISIBLE NONE;NEAR_Y NEAR_Y VISIBLE NONE"
)
arcpy.AddMessage("Make filtered Table View completed successfully")
arcpy.management.AddJoin(
in_layer_or_view=param1 + r"\PavedShoulder_Dissolve_DanglePoints",
in_field="OBJECTID",
join_table="PavedShoulder_GenerateNearTable_SameRouteDirection_View",
join_field="IN_FID",
join_type="KEEP_ALL",
index_join_fields="NO_INDEX_JOIN_FIELDS",
rebuild_index="NO_REBUILD_INDEX",
join_operation=""
)
arcpy.AddMessage("Add Join completed successfully")
# list all fields after join
print ("Fields after join:")
for field in arcpy.ListFields(param1 + r"\PavedShoulder_Dissolve_DanglePoints"):
print (field.name)
arcpy.management.CalculateField(
in_table="PavedShoulder_Dissolve_DanglePoints",
field="PavedShoulder_Dissolve_DanglePoints.MyNearX",
expression="!PavedShoulder__GenerateNearTable_03130017700_SameRouteDirection.NEAR_X!",
expression_type="PYTHON3",
code_block="",
field_type="TEXT",
enforce_domains="NO_ENFORCE_DOMAINS"
)
arcpy.AddMessage("Calculate Field MyNearX completed successfully") The output for printing the field names in my joined table is this :
Fields after join:
OBJECTID
Shape
RouteID
RouteDirection
SUM_Length_ft
ORIG_FID
DANGLE_LEN
POINT_X
POINT_Y
POINT_Z
MyNearX
MyNearY
PavedShoulder_Dissolve_DanglePoints_MyNearX
What is wrong with the joined fields that is causing the Calculate Field to give me an error?