jkappa

Can't Loop <-- I'm Stuck

Discussion created by jkappa on Dec 11, 2013
Latest reply on Dec 11, 2013 by jkappa
Hi,
I have some points (1000's!) and they are divided in groups. I have to draw lines between the parent and the children in each group.
I've been trying hard to loop through this, but I get different failing results such as getting only the first group of lines, the last one, the first one and empty outputs. The way I went about this is I created the feature classes, and my intention is selecting from the all feature class, append the selection to the group feature class, and then draw the lines. For example, this is the 'manual' method where I have to input each group ID:

GROUPID= 'A3W03R2533B'
arcpy.SelectLayerByAttribute_management("DEVICES","NEW_SELECTION","\"GROUPID\" = '" + GROUPID + "'")
arcpy.Append_management("DEVICES",GROUPID + "_ALL", "TEST", "", "")
arcpy.XYToLine_management(GROUPID + "_ALL",r"T:\Transfer\JorgeK\CCTV\DATA\\" + GROUPID + "_CONNECTOR.shp","CX","CY","PX","PY","RHUMB_LINE","GROUPID")
FeatureClassToFeatureClass_conversion (r"T:\Transfer\JorgeK\CCTV\DATA\\" + GROUPID + "_CONNECTOR.shp", r"T:\Transfer\JorgeK\CCTV\DATA\CCTV_CONN.gdb\\" + GROUPID + "\\", GROUPID + "_CONNECTIONS", "", "", "")


An example of a (one of many) failing loop:

#Loop that didn't work:
for ID in IDList:
    arcpy.SelectLayerByAttribute_management("DEVICES","NEW_SELECTION","\"GROUPID\" = ' " + ID + " ' ")
    arcpy.Append_management("DEVICES", ID + r"_ALL", "TEST", "", "")


Another failing loop:

#Loop that didn't work:
for ID in IDList:
    GROUPID= ID
    SELID= arcpy.SelectLayerByAttribute_management("DEVICES","NEW_SELECTION","\"GROUPID\" = '" + GROUPID + "'")
    for SEL in SELID:
        arcpy.Append_management("DEVICES",GROUPID + "_ALL", "TEST", "", "")
        arcpy.XYToLine_management(GROUPID + "_ALL",r"T:\Transfer\JorgeK\CCTV\DATA\\" + GROUPID + "_CONNECTOR.shp","CX","CY","PX","PY","RHUMB_LINE","GROUPID")


and I have many, many more. Anyway, I rolled up my sleeves and I am doing it manually, but if someone could clue me in as to why this is failing that would be awesome.
Thanks in advance!

JK

Outcomes