Quick way to Enable/Disable Attribute Rules at Database level

1068
4
09-28-2022 06:53 AM
Status: Open
PascalVezina
Occasional Contributor II

Good day,

It would be nice to be able to disable/enable all Attribute Rules at the database level.

When rules are present in database, and we have a workflow to create parcels from CAD lines, we don't necessarily know all the rules that are in the database we are working in. We don't want any rules to interfere with our "creation" process until it's time to "save", then we want the rules to apply.

If we could at the beginning of our workflow "disable" all attribute rules, then at the end of it, enable them back.

That would be great!

Thanks,

Tags (1)
4 Comments
DeanAnderson2

I agree - I had to create the following script to do that (currently does off but code for turning back on is also present.  

 

#0-EnableDisableAttributeRules.py
#
# Rules set to "Off" will enable attribute rules. 
#
# Inputs: All feature classes in Geodatabase (rules off) 
#   Geodatabase path built from a couple different variables 
#   leftovers from ArcMap/ArcInfo days 
#
# Outputs: All feature class in Geodatabase with attribute rules either turned on or off
# 
# Dean - 11/2020

import os,arcpy,time,datetime,traceback,shutil


def DisableRules(FC,ruletypes):
    desc = arcpy.Describe(fc).attributeRules
    for rule in desc:
        for rtype in ruletypes:
            rtypeesri = "esriART" + rtype
            print (rtypeesri)
            if rule.isEnabled == True and rule.type == rtypeesri:
                print("Disabling " + rtype + " rule: {}".format(rule.name))
                arcpy.DisableAttributeRules_management(fc, rule.name)
            
def EnableRules(FC,ruletypes):
    desc = arcpy.Describe(fc).attributeRules
    for rule in desc:
         for rtype in ruletypes:
            rtypeesri = "esriART" + rtype
            #print (rtypeesri)
            if rule.isEnabled == False and rule.type == rtypeesri:
                print("Enabling " + rtype + " rule: {}".format(rule.name))
                arcpy.EnableAttributeRules_management(fc, rule.name)

#######################################
                
try:
    logfile = "D:\\GISLogs\\DisableAttributeRulesAllOff.txt"
    arcpy.Delete_management (logfile) 
    logfile = open(logfile, "w")   
    starttime =  datetime.datetime.now()
    logfile.write ('\n' + '\n' + "StartTime:" + str(starttime) + '\n' + '\n')
    print ("StartTime:" + str(starttime))
    
    Rules = "Off" 

    Tile = 'T7-4'
    print (Tile)

    Library = 'P:\\ORMAProFabric\\TaxmapPolkV302\\'
    OutDb = Library + Tile + "\\Fabric\\TownEd.gdb"

    FabricPath = OutDb    
    arcpy.env.workspace = FabricPath
        
                
    datasets = arcpy.ListDatasets(feature_type='feature')
    datasets = [''] + datasets if datasets is not None else []
    ruletypes = ["Constraint","Calculation","Validation"]
    #ruletypes = ["Calculation"]
    
    for ds in datasets:
        for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
            print (fc) 
            path = os.path.join(arcpy.env.workspace, ds, fc)
            if Rules == "On":
                EnableRules(fc,ruletypes)
            else:
                DisableRules(fc,ruletypes)

except:
    badness = traceback.format_exc()
    print ('\n' + '\n' + "*** BADNESS ****" + '\n' + '\n')
    print (badness)
    
    logfile.write ('\n' + '\n' + "**** BADNESS *****" + '\n' + '\n')
    logfile.write (badness)
    
    logfile.close()
    

 

DeanAnderson2

Just to be sure - if this SDE it it is a SCHEMA change so you have other problems.  Changing a SCHEMA impacts everyone.  So... this works well in a geodatabase but not sure in a workflow how it would work for you. 

PascalVezina

You are probably right in an SDE environment, this should be applied only to the current user, not all users.

HusseinNasser2

There isn't an out of the box way to do it but you can script it with an options table as I show here https://community.esri.com/t5/attribute-rules-blog/how-to-toggle-constraint-and-calculation-attribut...