I am using ArcMap 10.1 and python to create cursor that starts at the one and only row of a polyline shapefile, some code runs to create a new feature based on the position of the exisiting feature, then adds this new feature as a second row. I then want the same code to run again on the newly created feature to then create a third...and so on.
However, the cursor stops working after the first run and the code completes, I guessing because the initial cursor doesn't take into account the newly created feature?
However I need this to run until a certain number of rows/features are created.
Is anyone able to help with this please?
Its as if I need to refresh the cursor or something, but I struggling to find a solution.
def addPolyline(cursor, array, sr): polyline = arcpy.Polyline(array, sr) cursor.insertRow((polyline,)) array.removeAll() import arcpy import os import math infc = ...path... shapefile = ...path... mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd,"*") spatialRef = arcpy.Describe(infc).spatialReference desc = arcpy.Describe(infc) shapefieldname = desc.ShapeFieldName rows = arcpy.SearchCursor(infc) with arcpy.da.InsertCursor(shapefile, ("SHAPE@",)) as cursor: polylineArray = arcpy.Array() for row in rows: < SOME CODE TO CREATE NEW FEATURE > newStartPoint = arcpy.Point(newStartX, newStartY) newEndPoint = arcpy.Point(newEndX, newEndY) polylineArray.add(newStartPoint) polylineArray.add(newEndPoint) addPolyline(cursor, polylineArray, spatialRef)