I have about 30 feature classes in an FGDB. I am looking for a script to remove all attribute indexes, as I will need to do this for multiple FGDBs eventually.
My file path is:
I started with this article
But got stuck at line 02
As a reference, here is the script from the link mentioned:
arcpy.env.workspace = "e:/crs/mobile/mobile.gdb" dsc = arcpy.Describe("sap") lstIndex = [i.name for i in dsc.Indexes][1:] print lstIndex arcpy.management.RemoveIndex("sap",lstIndex)
Line 2 is asking for a description of a feature class named "sap" inside the geodatabase. The script then puts the index names in a list starting with the second item. I assume this removes the FDO_OBJECTID from the list, but it keeps other items like FDO_SHAPE which you probably would not want to delete.
If you want to remove all attribute indexes from all feature classes in a geodatabase, the following will get the job done:
import arcpy import os gdb = # path to geodatabase walk = arcpy.da.Walk(gdb, datatype="FeatureClass") for root, _, fcs in walk: for fc in fcs: fc = os.path.join(root, fc) desc = arcpy.Describe(fc) OIDFieldName = desc.OIDFieldName shapeFieldName = desc.shapeFieldName idxs = [ i.name for i in desc.indexes if not any(f.name in (OIDFieldName, shapeFieldName) for f in i.fields) ] arcpy.RemoveIndex_management(fc, idxs)
As much as I provide the code above, I can't say I see the logic behind removing all attribute indexes for most or all feature classes in a geodatabase.
UPDATE: I had to alter my original code because I forgot that Remove Index will fail if either the OID or shape index is passed to it, both of which are returned when getting a list of indexes.