#For arcpy.RebuildIndexes_management, below is a script I copied directly off the ESRI help, and when running it, it errors out. #When researching the error, the folloing tech memo appeared: #https://support.esri.com/en/technical-article/000011553
#Below is my error message:
#RebuildIndexes raise e ExecuteError: ERROR 000087: Could not open table Southwest.GSW_SDE.Southwest_Net Failed to execute (RebuildIndexes).
#If I use the RebuildIndexes_management tool(red toolbox) in ArcMap it works, but not in a script form.....
#I am unclear how to apply the workaround described in the tech memo and I was hopeful someone could help......
#Once again, thank you for you assistance,
#Larry Adgate
#Golden State Water Company
#-------------------------------------------------------------------------------------------------------------------------------
import arcpy, os
workspace = "Database Connections\\SanDimas@gsw_sde.sde"
arcpy.env.workspace = workspace
dataList = arcpy.ListTables() + arcpy.ListFeatureClasses()
for dataset in arcpy.ListDatasets("", "Feature"):
arcpy.env.workspace = os.path.join(workspace,dataset)
dataList += arcpy.ListFeatureClasses() + arcpy.ListDatasets()
arcpy.env.workspace = workspace
userName = arcpy.Describe(workspace).connectionProperties.user.lower()
userDataList = [ds for ds in dataList if ds.lower().find(".%s." % userName) > -1]
print userDataList
arcpy.RebuildIndexes_management(workspace, "NO_SYSTEM", userDataList, "ALL")
print('Rebuild Complete')
Solved! Go to Solution.
Been a while since I ran into this issue, so not exactly sure what I figured out, but here is the modified code I use that has been working just fine. Give it a try, see if it resolves you issue:
# Get a list of all the datasets the user has access to.
# First, get all the stand alone tables, feature classes and rasters.
arcpy.env.workspace = workspace
dataList = arcpy.ListTables() + arcpy.ListFeatureClasses() + arcpy.ListRasters()
# Next, for feature datasets get all of the datasets and featureclasses
# from the list and add them to the master list.
for dataset in arcpy.ListDatasets("", "Feature"):
ptd = arcpy.env.workspace = os.path.join(workspace,dataset)
for ds in arcpy.ListFeatureClasses():
dataList.append(os.path.join(ptd,ds))
arcpy.env.workspace = workspace
# Process: Rebuild Indexes
arcpy.RebuildIndexes_management(PublicWorks_OS_sde,"SYSTEM",dataList,"ALL")
PS, notice how much easier it is to read/decipher when in the syntax highlighter.....
Been a while since I ran into this issue, so not exactly sure what I figured out, but here is the modified code I use that has been working just fine. Give it a try, see if it resolves you issue:
# Get a list of all the datasets the user has access to.
# First, get all the stand alone tables, feature classes and rasters.
arcpy.env.workspace = workspace
dataList = arcpy.ListTables() + arcpy.ListFeatureClasses() + arcpy.ListRasters()
# Next, for feature datasets get all of the datasets and featureclasses
# from the list and add them to the master list.
for dataset in arcpy.ListDatasets("", "Feature"):
ptd = arcpy.env.workspace = os.path.join(workspace,dataset)
for ds in arcpy.ListFeatureClasses():
dataList.append(os.path.join(ptd,ds))
arcpy.env.workspace = workspace
# Process: Rebuild Indexes
arcpy.RebuildIndexes_management(PublicWorks_OS_sde,"SYSTEM",dataList,"ALL")
PS, notice how much easier it is to read/decipher when in the syntax highlighter.....
Thank You so much, this worked perfectly
Larry Adgate