Instead of using a codeblock in CalculateField, open an updateCursor in a Python script and put the code in there.You have to extract out the shape as an object, rebuild a new object and update the shape field.A script can be much easier to write, with exception traps. # POS transect with measures
posArray = arcpy.Array()
for transit in dPOS.keys():
for mrk in dPOS[transit]:
ta,tb = trans(mrk[0],mrk[1])
posArray.add(arcpy.Point(ta,tb,mrk[2],mrk[3]))
rowPOS = curPOS.newRow()
rowPOS.mark = transit.upper()
rowPOS.plotid = plotid
rowPOS.plotmark = plotid + transit.upper()
rowPOS.shape = posArray
curPOS.insertRow(rowPOS)
posArray.removeAll()
In this snippet I am looping around a dictionary of coordinates (dPOS), transforming them and building an array of points in posArray for the polyline feature. I am creating the lines, not updating.Note the four values ta,tb,mrk[2],mrk[3] which are x,y,z,m values.In your case you would be extracting the current values from the shape using an update cursor with something likeHere is a more complex example showing how you have to iterate over the parts in a polyline to get to the vertices.# fillDonut.py
# frequent forum request to fill holes
# use an Update Cursor to edit polys with donuts
# 22 May 2010
# Kim Ollivier kimo@ollivier.co.nz
# (c) Creative Commons 3.0 (Attribution)
# Method
# ------
# Polygon features are stored as:
# [[pnt,pnt,pnt,pnt,,pnt,pnt,pnt,pnt][pnt,pnt,pnt,pnt]]
# Parts are separate lists inside the feature object array
# null point in a part indicates donut ring(s) follow
# So just step through and truncate at first null pnt per part,
# re-assemble parts into a polygon
# Update feature if a donut found, otherwise continue
# Input is a layer so can use selection in Arcmap
# could also put on menu at ArcMap 10
# can be back-ported to 9.3
# 4 June 2010
# added iter lambda function for part array because isn't interable
# cleared polyOuter buffer earlier to fix logic for multiple parts
import arcpy,sys
def filldonut(inlay) :
'''Edits a layer in-place
fills all features with donuts
requires a layer to honour
selected features
'''
desc = arcpy.Describe(inlay)
shapefield = desc.ShapeFieldName
rows = arcpy.UpdateCursor(inlay)
n = 0
polyGeo = arcpy.Array() # to hold edited shape
polyOuter = arcpy.Array() # to hold outer ring
for row in rows:
feat = row.getValue(shapefield)
qInterior = False
for partNum in range(feat.partCount) :
part = feat.getPart(partNum)
for pt in iter(lambda:part.next(),None) : # iter stops on null pt
polyOuter.append(pt)
if part.count > len(polyOuter) :
qInterior = True
polyGeo.append(polyOuter) # reassemble each part
polyOuter.removeAll() # ready for next part
if qInterior : # in any part of this feature, otherwise skip update
n+=1
row.setValue(shapefield,polyGeo)
rows.updateRow(row)
polyGeo.removeAll()
del rows,row
msg = "Features with interior ring filled "+str(n)
arcpy.AddMessage(msg)
arcpy.AddMessage("Refresh view to see donuts disappear!")
#----------------------------------------------------
if __name__ == '__main__' :
inlay = sys.argv[1] # arcpy.GetParameterAsText(0)
desc = arcpy.Describe(inlay)
if desc.shapetype != 'Polygon' :
arcpy.AddError(inlay + " Not a polygon class")
else :
filldonut(inlay)
arcpy.RefreshGraphics()
(Unfortunately it is possible to fool this code with complex nested imbedded holes in multipart polygons. but it works for simple cases.)