4

I have a list of unused/unassigned domains in table format. It's actually a table inside a GDB. I want to build a model that iterates through this table and deletes the domain.

Is this possible with ModelBuilder?

I tried to create a field value iterator, however, it won't let me link it up with the Delete Domain tool.

I know it's possible with python, but has anyone successfully attempted this with ModelBuilder.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Aug 27, 2015 at 14:42

1 Answer 1

3

I wasn't able to find the Model builder answer, but I managed to create a script in python that did the job.

Here it is:

##domain clean up script
##Created by: Ruchira Welikala
##Date: Aug 27, 2015
import arcpy
from arcpy import env
#Workspace where domains will be deleted from
gdbConnName = "Database Connections\\ProductionDB.sde"
#Workspace/Table where list of unused domains are located
UnusedDmnListTable = "C:\Scratch Workspace\domain_List.gdb\A_UnusedDomains"
#Field name that you're running the cursor on
fieldName = "name"
#Cursor initialization. Set the cursor to the table
cursor = arcpy.SearchCursor(UnusedDmnListTable)
txtfile = open('DomainsNOTDeleted.txt','w')
#Loop through and delete domains from workspace
for row in cursor:
 try:
 print "Deleting domain: " + (row.getValue(fieldName))
 arcpy.DeleteDomain_management(gdbConnName, (row.getValue(fieldName)))
 print "Deleted:" + (row.getValue(fieldName))
 except Exception:
 print "Domain " + row.getValue(fieldName) + " was not deleted."
 txtfile.write(row.getValue(fieldName) + "\n")
 continue
txtfile.close()
Paul
11.7k1 gold badge31 silver badges48 bronze badges
answered Aug 28, 2015 at 16:34
1
  • You should delete your cursor (del row, cursor) after you are done using it to ensure proper closure. Or better yet, since you are on 10.1+, use da.SearchCursor with a with statement, which automatically closes and is considerably more robust and efficient. Commented Aug 28, 2015 at 17:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.