<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Migration of code from 2.x to 3.x in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/migration-of-code-from-2-x-to-3-x/m-p/1038791#M60495</link>
    <description>&lt;P&gt;In trying to migrate from 2.x to 3.x, I am trying to update a segment of code and my troubleshoot has ran its limits with Google. I am trying to remove domains from fields in various feature classes below. My error, in particular, comes from the image below where the error I get is the&amp;nbsp;&lt;STRONG&gt;'NoneType' object is not callable.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Brian_McLeer_0-1616179244707.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/8966i72A450DC0921D7FC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Brian_McLeer_0-1616179244707.png" alt="Brian_McLeer_0-1616179244707.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Full Code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;		# Comments
		arcpy.AddMessage("Removing All Domains..." +'\n')
		txtFile.write("Removing All Domains..." +'\n')

		#Set workspace environment to geodatabase
		arcpy.env.workspace = "D:\\WorkSpace\\WebReporter\\Workspace.gdb"
		myGDB = "D:\\WorkSpace\\WebReporter\\Workspace.gdb"

		#Get list of feature classes in geodatabase
		FCs = arcpy.ListFeatureClasses()

		#Loop through feature classes in list
		for FC in FCs:

			#List fields in feature class
			fields = arcpy.ListFields(FC)

			#Loop through fields
			for field in fields:

				#Check if field has domain
				if (field.domain != "" and field.domain != 'EnabledDomain' and field.domain != 'AnnotationStatus'):

					#Print feature class, field, domain name
					print (FC, field.name, field.domain)
					arcpy.RemoveDomainFromField_management(FC, field.name)

				# Get domains that are assigned to a field
		domains_used = []
		for dirpath, dirnames, filenames in arcpy.da.Walk(myGDB, datatype=["FeatureClass", "Table"]):
			for filename in filenames:
				print ("Checking {}".format(os.path.join(dirpath, filename)))
				## Check for normal field domains
				for field in arcpy.ListFields(os.path.join(dirpath, filename)):
					if field.domain:
						domains_used.append(field.domain)
						## Check for domains used in a subtype field
								# Comments
				arcpy.AddMessage("I got to here..." +'\n')
				txtFile.write("I got to here..." +'\n')
				subtypes = arcpy.da.ListSubtypes(os.path.join(dirpath, filename))
				for stcode, stdict in subtypes.items():
					if stdict.get('keys')()()("SubtypeField") != u'':
						for field, fieldvals in stdict.get('keys')("FieldValues").items():
							if not fieldvals[1] is None:
								domains_used.append(fieldvals[1].name)


							# Get domains that exist in the geodatabase
		domains_existing = [dom.name for dom in arcpy.da.ListDomains(myGDB)]

		# Find existing domains that are not assigned to a field  
		domains_unused = set(domains_existing) ^ set(domains_used)
		print ("{} unused domains in {}".format(len(domains_unused), myGDB))
		for domain in domains_unused:
			arcpy.DeleteDomain_management(myGDB, domain)
			print ("{} deleted".format(domain)  )

		# Comments
		arcpy.AddMessage("Removing All Domains Complete..." +'\n')
		txtFile.write("Removing All Domains Complete..." +'\n')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 19 Mar 2021 18:42:36 GMT</pubDate>
    <dc:creator>Brian_McLeer</dc:creator>
    <dc:date>2021-03-19T18:42:36Z</dc:date>
    <item>
      <title>Migration of code from 2.x to 3.x</title>
      <link>https://community.esri.com/t5/python-questions/migration-of-code-from-2-x-to-3-x/m-p/1038791#M60495</link>
      <description>&lt;P&gt;In trying to migrate from 2.x to 3.x, I am trying to update a segment of code and my troubleshoot has ran its limits with Google. I am trying to remove domains from fields in various feature classes below. My error, in particular, comes from the image below where the error I get is the&amp;nbsp;&lt;STRONG&gt;'NoneType' object is not callable.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Brian_McLeer_0-1616179244707.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/8966i72A450DC0921D7FC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Brian_McLeer_0-1616179244707.png" alt="Brian_McLeer_0-1616179244707.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Full Code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;		# Comments
		arcpy.AddMessage("Removing All Domains..." +'\n')
		txtFile.write("Removing All Domains..." +'\n')

		#Set workspace environment to geodatabase
		arcpy.env.workspace = "D:\\WorkSpace\\WebReporter\\Workspace.gdb"
		myGDB = "D:\\WorkSpace\\WebReporter\\Workspace.gdb"

		#Get list of feature classes in geodatabase
		FCs = arcpy.ListFeatureClasses()

		#Loop through feature classes in list
		for FC in FCs:

			#List fields in feature class
			fields = arcpy.ListFields(FC)

			#Loop through fields
			for field in fields:

				#Check if field has domain
				if (field.domain != "" and field.domain != 'EnabledDomain' and field.domain != 'AnnotationStatus'):

					#Print feature class, field, domain name
					print (FC, field.name, field.domain)
					arcpy.RemoveDomainFromField_management(FC, field.name)

				# Get domains that are assigned to a field
		domains_used = []
		for dirpath, dirnames, filenames in arcpy.da.Walk(myGDB, datatype=["FeatureClass", "Table"]):
			for filename in filenames:
				print ("Checking {}".format(os.path.join(dirpath, filename)))
				## Check for normal field domains
				for field in arcpy.ListFields(os.path.join(dirpath, filename)):
					if field.domain:
						domains_used.append(field.domain)
						## Check for domains used in a subtype field
								# Comments
				arcpy.AddMessage("I got to here..." +'\n')
				txtFile.write("I got to here..." +'\n')
				subtypes = arcpy.da.ListSubtypes(os.path.join(dirpath, filename))
				for stcode, stdict in subtypes.items():
					if stdict.get('keys')()()("SubtypeField") != u'':
						for field, fieldvals in stdict.get('keys')("FieldValues").items():
							if not fieldvals[1] is None:
								domains_used.append(fieldvals[1].name)


							# Get domains that exist in the geodatabase
		domains_existing = [dom.name for dom in arcpy.da.ListDomains(myGDB)]

		# Find existing domains that are not assigned to a field  
		domains_unused = set(domains_existing) ^ set(domains_used)
		print ("{} unused domains in {}".format(len(domains_unused), myGDB))
		for domain in domains_unused:
			arcpy.DeleteDomain_management(myGDB, domain)
			print ("{} deleted".format(domain)  )

		# Comments
		arcpy.AddMessage("Removing All Domains Complete..." +'\n')
		txtFile.write("Removing All Domains Complete..." +'\n')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 18:42:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migration-of-code-from-2-x-to-3-x/m-p/1038791#M60495</guid>
      <dc:creator>Brian_McLeer</dc:creator>
      <dc:date>2021-03-19T18:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Migration of code from 2.x to 3.x</title>
      <link>https://community.esri.com/t5/python-questions/migration-of-code-from-2-x-to-3-x/m-p/1038800#M60496</link>
      <description>&lt;P&gt;If you set a breakpoint on the line above (or a few lines above and step over to check your values) and debug, what values get assigned to the variables field and fieldvals?&amp;nbsp; That should tell you if fieldvals[1] is null or not and possibly give you a clue where something may be broken.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 18:59:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/migration-of-code-from-2-x-to-3-x/m-p/1038800#M60496</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-03-19T18:59:29Z</dc:date>
    </item>
  </channel>
</rss>

