Skip to main content
6 of 7
Removed chit chat as per Tour
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

I know you can use an iterator in model builder, but if you prefer to use python here is something I came up with. Add the script to a toolbox with the parameters in order as Input shpfile, fields(multivalue,obtained from input), and workspace. This script will split the shapefile into multiple shapefiles based on the fields you select, and output them into a folder of your choice.

import arcpy, re

arcpy.env.overwriteOutput = True

Input = arcpy.GetParameterAsText(0)  
Flds = "%s" % (arcpy.GetParameterAsText(1)) 
OutWorkspace = arcpy.GetParameterAsText(2) 


myre = re.compile(";")
FldsSplit = myre.split(Flds)

sort = "%s A" % (FldsSplit[0])
rows = arcpy.SearchCursor(Input, "", "", Flds, sort)

for row in rows:
    var = []
    for r in range(len(FldsSplit)):
        var.append(row.getValue(FldsSplit[r]))
    Query = ''
    Name = ''
    for x in range(len(var)):
        if x == 0:
            fildz = FldsSplit[x]
            Name = var[x] + "_"
            Query += (""" "%s" = '%s'""" % (fildz, var[x]))
        if x > 0:
            fildz = FldsSplit[x]
            Name += var[x] + "_"
            Query += (""" AND "%s" = '%s' """ % (fildz, var[x]))
    OutputShp = OutWorkspace + r"\%s.shp" % (Name)
    arcpy.Select_analysis(Input, OutputShp, Query)
Isaac
  • 61
  • 1
  • 4