Cannot delete domain ... with a twist

4756
4
04-10-2014 09:11 AM
Waan
by
Occasional Contributor
Hi all

I'm working in a file geodatabase and deleting some duplicate domains that have crept in. I've successfully used Python to identify which domains are associated with which fields and, after rejiggering them, have deleted several--except for one, D_LABEL_TYP_1. It does not appear to be associated with any table or feature class (within or without the sole feature dataset) but I still cannot delete it. When I do try to delete it, the error I get ("Failed to delete a domain from the database. The domain is used by an attribute rule.") doesn't jibe with what my Python results are telling me. To wit, here's the exact Python I'm using:

import arcpy
arcpy.env.workspace = "C:\Workspace\template.gdb"


Checking feature classes within the feature dataset:
for FD in arcpy.ListDatasets():
 for FC in arcpy.ListFeatureClasses("","",FD):
  for field in arcpy.ListFields(FC):
   if field.domain == "D_LABEL_TYP_1":
    print FC, field.name, field.domain


Checking feature classes outside the feature dataset:
del FD, FC, field
for FC in arcpy.ListFeatureClasses():
 for field in arcpy.ListFields(FC):
  if field.domain == "D_LABEL_TYP_1":
   print FC, field.name, field.domain


And checking all tables:
del FC, field
for table in arcpy.ListTables():
 for field in arcpy.ListFields(table):
  if field.domain == "D_LABEL_TYP_1":
   print table, field.name, field.domain


I've also tried using just "if field.domain:", which gives me a list of every table-field-domain combination--but I still don't find any fields having the D_LABEL_TYP_1 domain. I've also checked to be sure this domain doesn't have any trailing spaces in its name.

Any ideas why ArcGIS thinks this domain is still attached to an attribute table? As its name suggests, this file geodatabase is a template we use for multiple projects and it's important to get it squared away before we use it.

Thanks, -W
0 Kudos
4 Replies
MarcoBoeringa
MVP Regular Contributor
Googling for "D_LABEL_TYP_1" returns two XML metadata results possibly associated with a FEMA Floodmap application? The results show a domain being associated with fields named "S_Label_Ld" and "S_Label_Pt". Do you have similar named fields in your geodatabase?

Additionally, do you possibly use subtypes? Each subtype can have its own domain, even within one field. So searching for fields may not be enough, you may need to check subtypes.
0 Kudos
Waan
by
Occasional Contributor
Marco-

You're correct, I ended up finding many subtypes using the domain in question. I ended up checking them manually as I'm not savvy enough with ArcPy to figure out how to list domains with subtypes.

ArcPy.da.ListSubtypes() proved to be of some help:
http://resources.arcgis.com/en/help/main/10.1/index.html#//018w00000021000000

It'd be great if someone handy with Python demonstrates how to the domains associated with each subtype in each feature class.


Also: the ArcGIS Ideas site has an idea to create a "Locate Domain" tool. This would make life easier for those of us who work with lots of field and/or subtype domains:
https://c.na9.visual.force.com/apex/ideaView?id=08730000000c1vSAAQ

-W
0 Kudos
XanderBakker
Esri Esteemed Contributor

While looking for some problems I've encountered I came across this thread. Not sure if anyone is still "listening" to this thread, but thought I would post some code I have to list subtypes and correnponding default field values (and releted domains in the subtype). Maybe it is useful for someone...

def main():

    # import arceditor

    import arcpy

    import os

    lst_amb = ["DLLO 9.3.1", "TEST 9.3.1", "PROD 9.3.1",

               "DLLO 10.1", "TEST 10.1", "PROD 10.1"]

    # dictionary with connection files

    dct_conn = {"DLLO 9.3.1":r"C:\Users\xbakker\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Desarrollo 9.3.1 (GEOGENESIS).sde",

                "TEST 9.3.1": r"C:\Users\xbakker\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Pruebas 9.3.1 (GEOGENESIS).sde",

                "PROD 9.3.1": r"C:\Users\xbakker\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Produccion 9.3.1 (GEOGENESIS).sde",

                "DLLO 10.1": r"C:\Users\xbakker\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Desarrollo 10.1.sde",

                "TEST 10.1": r"C:\Users\xbakker\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Pruebas 10.1.sde",

                "PROD 10.1": r"C:\Users\xbakker\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Produccion 10.1.sde"}

    # set encoding to utf-8

    import sys

    reload(sys)

    print sys.getdefaultencoding()

    def_enc = sys.getdefaultencoding()

    sys.setdefaultencoding('utf8')

    # format of TXT report with subtypes

    report = r"D:\Xander\Genesis\Domains\report_subtypes_v4.txt"

    with open(report, "w") as f:

        f.write("Database\tDataset\tFeatureClass\tSubtypeField\tSubtypeCode\tSubtypeName\tIsDefaultValue\tFieldName\tFieldDefaultValue\tFieldDomain\n")

        # loop through databases

        for amb in lst_amb:

            ws = dct_conn[amb]

            arcpy.env.workspace = ws

            lst_fds = arcpy.ListDatasets()

            # loop through feature datasets

            for fds in lst_fds:

                fcs = arcpy.ListFeatureClasses(feature_dataset=fds)

                if len(fcs) != 0:

                    # loop through each featureclass en current feature dataset

                    for fc in fcs:

                        try:

                            # list subtypes

                            subtypes = arcpy.da.ListSubtypes(os.path.join(ws,fds,fc))

                            # colect info on subtype

                            for stcode, stdict in subtypes.iteritems():

                                if 'Default' in stdict:

                                    IsDefaultValue = stdict['Default']

                                else:

                                    IsDefaultValue = ""

                                if 'Name' in stdict:

                                    SubtypeName = stdict['Name']

                                else:

                                    SubtypeName = ""

                                if 'SubtypeField' in stdict:

                                    SubtypeField = stdict['SubtypeField']

                                    if SubtypeField != None and SubtypeField != "":

                                        # list default field value and field details (like related domain)

                                        if 'FieldValues' in stdict:

                                            fields = stdict['FieldValues']

                                            for fieldname, fieldvals in fields.iteritems():

                                                FieldDefaultValue = fieldvals[0]

                                                if not fieldvals[1] is None:

                                                    domainname = fieldvals[1].name

                                                else:

                                                    domainname = ""

                                                f.write('{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\n'.format(

                                                         amb, fds, fc, SubtypeField, stcode, SubtypeName, IsDefaultValue,

                                                         fieldname, FieldDefaultValue, domainname))

                        except:

                            f.write('{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\n'.format(

                                    amb, fds, fc, "Error", -1, "Error", "Error",

                                    "Error", -1, "Error"))

    # restore default settings

    sys.setdefaultencoding(def_enc)

if __name__ == '__main__':

    main()

Kind regards, Xander

MarcoBoeringa
MVP Regular Contributor
It'd be great if someone handy with Python demonstrates how to the domains associated with each subtype in each feature class.

Also: the ArcGIS Ideas site has an idea to create a "Locate Domain" tool. This would make life easier for those of us who work with lots of field and/or subtype domains:
https://c.na9.visual.force.com/apex/ideaView?id=08730000000c1vSAAQ


There are several tools out there that can be of help. Most notably something like for example X-Ray for ArcGIS. It allows you to create Excel spreadsheets or XML workspace documents with data on database structure. You could than use Excel or a text editor to search for a certain domain. X-Ray also allows you to manipulate the database model:

X-Ray for ArcCatalog (ArcGIS 10.2)

Another option is Geodatabase Diagrammer, that works with Visio:

Geodatabase Diagrammer for 10X

For this latter tool, please also see the remarks by users below the item about a possible need to save the template Visio documents to a new version of Visio, before you can use it.
0 Kudos