2 Replies Latest reply on Feb 23, 2012 11:42 AM by recurvata

    For Loop ?

      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.SelectLayerByAttribute_management (fc1,"CLEAR_SELECTION")

      coordList = []

      arcpy.FeatureVerticesToPoints_management("hidden", "vertices", "MID")
      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


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

      for feature in coordList:
          point.X = feature[0]
          point.Y = feature[1]

      polyline = arcpy.Polyline(array)
      arcpy.CopyFeatures_management(polyline, fc2)
        • Re: For Loop ?
          enclose your code in the Code block symbol in the html editor (ie #)
          This line will fail
          env.workspace = "D:\pomme de terre 2\pomme de terre2.gdb"
          since you have to use raw notation
          env.workspace = r"D:\pomme de terre 2\pomme de terre2.gdb"
          or double backslashes or single foreslashes in python
          ie  env.workspace = "D:\\pomme de terre 2\\pomme de terre2.gdb"
          may the spud be with you
          • Re: For Loop ?
            One advantage of formatting using code tags like Dan suggests is that others here can see if indenting is the problem. The way it's posted now, it looks like none of the code under your for statements is indented. That will cause a logic error, in that Python thinks you have an empty for loop and just moves sequentially through your code without looping.

            On the other hand, maybe your actual code is indented, but it doesn't display in the forum that way if you haven't used code tags. In that case you wouldn't have the no indent problem, but no one here can tell that.