ArcMap 10.7.1 — Oracle 18c SDE.St_Geometry — Polyline FC
I have an ArcPy function that works as expected in a standalone ArcPy script (PyScripter):
def new_shape(geom):
spatial_reference = geom.spatialReference
parts = arcpy.Array()
for i in range(geom.partCount):
part = geom.getPart(i)
points = arcpy.Array()
for point in part:
point.M = geom.measureOnLine(point)
points.append(point)
parts.append(points)
return arcpy.Polyline(parts, spatial_reference)That function works correctly, including the following for loop. It returns a reconstructed shape to the main ArcPy Script.
for point in part:
point.M = geom.measureOnLine(point)
points.append(point)
However, when I use that same function in the Field Calculator, the script runs without errors, but it returns an empty shape.
The problem seems to be the for loop: for point in part:. When I debug the code, I can see that the script doesn't enter the for loop.
I was able to work around the issue by using a different style of for loop and the .getObject() array property. Now, the script enters the for loop and constructs the shape from the points, as expected:
for j in range(part.count):
point = part.getObject(j)
point.M = geom.measureOnLine(point)
points.append(point)
Question:
Why does for point in part: work in a standalone ArcPy script, but not in the Field Calculator?
I would like to understand this better — in case I'm doing something wrong.