DMS2

Listing only attribute indexes

Discussion created by DMS2 on Nov 21, 2013
Latest reply on Nov 21, 2013 by jamesfreddyc
I need a script to check the attribute indexes of every feature class in a geodatabase, to delete or create the indexes to fit my needs.

I've used the ListIndexes arcpy function but it lists not only attribute indexes but also spatial indexes.

Is there a way to list only attribute indexes?

import arcpy

fields =  "OBJECTID"
index_name =  "FDO_OBJECTID"
unique_vals = "UNIQUE"
order = "ASCENDING"
FSO_OID = False

try:

    gdb = arcpy.GetParameterAsText(0) 
    arcpy.env.workspace = gdb

    fdatasets = arcpy.ListDatasets()
    for fdataset in fdatasets:
        arcpy.AddMessage("Feature dataset: " + fdataset)
        arcpy.AddMessage('-' * 40)
        fcs = arcpy.ListFeatureClasses('','',fdataset)
        for fc in fcs:
            indexes = arcpy.ListIndexes(fc) # ----> Lists both attribute and spatial indexes!!!
            for index in indexes:
                if (index.name <> index_name):
                    arcpy.RemoveIndex_management(fc, index.name)
                else:
                    FSO_OID = True
            if FSO_OID == False:
                arcpy.AddIndex_management(fc, fields, index_name, unique_vals, order)

except:
    arcpy.GetMessages(2)

Outcomes