Maybe you are new at this and you are missing that you need to add more code after line 26.
Let's see... something like this... I sort of rewrote the whole thing and then created a FGDB to test it since I have not used Attribute rules yet. It worked for me.
Apparently you cannot put tables inside feature datasets, so I did not look for that in the first for loop.
import arcpy
import os
gdb = r"C:\data\gis.sde"
aaPath = r"C:\data\AttributeRules"
def export_attributes(item, ruleFile):
attRules = arcpy.Describe(item).attributeRules
if len(attRules) == 0:
arcpy.AddMessage("No rules found in %s" % item)
return True # Nothing to do
try:
arcpy.management.ExportAttributeRules(item, ruleFile)
except Exception as e:
arcpy.AddMessage("FAILED to create %s, %s" % (ruleFile, e))
return False
arcpy.AddMessage("SUCCESSFULLY created %s" % ruleFile)
return True
arcpy.env.workspace = gdb
arcpy.env.overwriteOutput = True
for ds in arcpy.ListDatasets("*"):
for fc in arcpy.ListFeatureClasses("*", feature_dataset=ds):
fcPath = os.path.join(ds, fc)
rules = os.path.join(aaPath, fc+'_AA.csv')
export_attributes(fcPath, rules)
for fc in arcpy.ListFeatureClasses("*"):
rules = os.path.join(aaPath, fc+'_AA.csv')
export_attributes(fc, rules)
for table in arcpy.ListTables("*"):
rules = os.path.join(aaPath, table+'_AA.csv')
export_attributes(table, rules)
Caveat, I tested it with a file GDB since my SDE database does not have any attribute rules in it yet.
Here is a sample CSV file it generated,
NAME,DESCRIPTION,TYPE,SUBTYPE,FIELD,ISEDITABLE,TRIGGERINSERT,TRIGGERDELETE,TRIGGERUPDATE,SCRIPTEXPRESSION,ERRORNUMBER,ERRORMESSAGE,EXCLUDECLIENTEVALUATION,ISENABLED,BATCH,SEVERITY,TAGS,CATEGORY,CHECKPARAMETERS
New Item,,CALCULATION,,Color,True,True,False,False,""Chartreuse"",,,False,True,False,,,,"{""type"":""PropertySet"",""propertySetItems"":[]}"