Sunday 19 February 2017

arcpy - Listing feature classes with active domains?



I have an Esri file geodatabase with attribute domains defined. I need to delete some of the attribute domains but can't because "The domain is used by an attribute rule.". How might I discover which feature class(es) are using the domains?


Executing: DeleteDomain R:\v5\YT_Canvec.gdb Permanency
Start Time: Thu May 19 11:01:02 2011
ERROR 999999: Error executing function.
The domain is used by an attribute rule.
Failed to execute (DeleteDomain).
Failed at Thu May 19 11:01:02 2011 (Elapsed Time: 0.00 seconds)

There are over a hundred feature classes in the geodatabase, interactively looking at the FC field properties for each one is a non-starter. The gdb is too large to convert to a personal gdb and go in the back door with ms-access (a dodgy method anyway).





(2011-May-26): Another way to phrase this is "which Feature Class is using domain X?"



Answer



To answer the question of handling feature classes with subtypes, it is possible with arcpy (10.1+).


arcpy.env.workspace = your_gdb

for FC in arcpy.ListFeatureClasses():
for stcode, stdict in list(arcpy.da.ListSubtypes(FC).items()):
for stkey in list(stdict.keys()):
if stkey == 'FieldValues':
for field, fieldvals in list(stdict[stkey].items()):

if fieldvals[1] is not None:
print(
"{},{},{},{}".format(FC,
'None' if stcode == 0 else stdict['Name'],
field,
fieldvals[1].name))

The subtype code, stcode, will be zero if there are no subtypes, so the code prints out 'None'.


The subtypes dictionary has more to it, so inspect it in code.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...