This question already has an answer here:
I am trying to update Z values of the vertices of the polygon shape. The script bellow works for polygons without multiparts and donuts. If I run this script for polygon shape that contains multiparts and donuts, I get error. How can I make it work?
import arcpy fc = r"C:\Scratch\fcTest.shp" # Get Spatial Reference of dataset desc = arcpy.Describe(fc) sr = desc.spatialReference with arcpy.da.UpdateCursor(fc, ["SHAPE@"]) as cursor: for row in cursor: # Get Geometry geom = row # Create an empty array object arr = arcpy.Array() # Read points, if Z is found to be zero reset it to 1 for part in geom: for pnt in part: if not pnt: arr.add(None) continue if pnt.Z == 0: pnt.Z = 1.0 # Add updated point to Array arr.add(pnt) # Construct new polygon geometry from array whilst setting spatial reference and indicating it has Z newpoly = arcpy.Polygon(arr,sr,True) #Update row cursor.updateRow([newpoly])
Traceback (most recent call last): File "C:\Scratch\fcTest.py", line 21, in <module> if pnt.Z == 0: AttributeError: 'NoneType' object has no attribute 'Z' >>>