pink34

For Loop ?

Discussion created by pink34 on Feb 23, 2012
Latest reply on Feb 23, 2012 by recurvata
At the first for loop, it only evaluates ID_1=273. What is the missing point? I want to do all the statement for all features with ID_1s at the attribute table. Please give some feedbacks. Thank you.

import arcpy
from arcpy import env
env.workspace = "D:\pomme de terre 2\pomme de terre2.gdb"
env.overwriteOutput = 1

fc1 = "Flowline"
fc2 = "New_Poyline"

for a in range(1,274):

        obj = "ID_1=%s" % (a)

arcpy.SelectLayerByAttribute_management (fc1,"NEW_SELECTION",obj)
arcpy.SelectLayerByLocation_management(fc1,"INTERSECT",fc1)
arcpy.CopyFeatures_management(fc1,"hidden")
arcpy.SelectLayerByAttribute_management (fc1,"CLEAR_SELECTION")

coordList = []

arcpy.FeatureVerticesToPoints_management("hidden", "vertices", "MID")
arcpy.AddXY_management("vertices")
rows = arcpy.SearchCursor("vertices")

for row in rows:
    X = row.getValue("POINT_X")
    Y = row.getValue("POINT_Y")
    coordList.append([X, Y])

del row, rows

coordList.sort()

point = arcpy.Point()
array = arcpy.Array()

for feature in coordList:
    point.X = feature[0]
    point.Y = feature[1]
    array.add(point)

polyline = arcpy.Polyline(array)
   
array.removeAll()
arcpy.Delete_management("vertices")
arcpy.Delete_management("hidden")
arcpy.CopyFeatures_management(polyline, fc2)

Outcomes