AnsweredAssumed Answered

ArcMap10.1 Loop through a unique list to create new layers for each unique name.

Question asked by schritto on Apr 10, 2014
Latest reply on Apr 10, 2014 by schritto
I have only taken one GIS class that used python so this is messy!

I was able to get the unique list from the attributes table under the column 'Layer'. Next I need the program to use each unique name from that list, select by attributes and create a new layer file for each unique name. I have the count in there because there are 33 different unique names in that list. I know there is a better way to do this, I just don't remember how.

I realize my code is far from perfect so if you have other questions or tips please don't hesitate to ask.

import arcpy, sys, os, traceback

fc = r"C:\Users\Drew\Desktop\Montpelier\PythonTest\PythonGDB.gdb\dshline_Project"
field = ["Layer"]
valueList = []

#Use search cursor to aquire a list of unique values
    with arcpy.da.SearchCursor(fc, field) as cursor:
        for row in cursor:

    uniqueSet = set(valueList)
    uniqueList = list(uniqueSet)

    del cursor

    count = 0
    name = uniqueList[count]
    outputname = r"C:\Users\Drew\Desktop\Montpelier\PythonTest\PythonGDB.gdb\"" + name
    if count < 34:
        arcpy.MakeFeatureLayer_management (r"C:\Users\Drew\Desktop\Montpelier\PythonTest\PythonGDB.gdb\dshline_Project", "layer")
        arcpy.SelectLayerByAttribute_management("layer","NEW_SELECTION", """Layer" = """ + name)

##        arcpy.SelectLayerByAttribute_management("dshline_Project","NEW_SELECTION",""""Layer" = 'ANNOT'""")

        count += 1
        print "Done"

Please Help!