<?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 RuntimeError: 'in_table' is not a table or a featureclass in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/runtimeerror-in-table-is-not-a-table-or-a/m-p/1058526#M61152</link>
    <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I've been working on a script that will take a group of manually selected features and utilize UpdateCursor to update a field based on three other columns. As of right now, I'm programming it so that messages appear to provide proof of concept.&lt;STRONG&gt; The goal of this is to automate what was a field calculation process into a python add in button.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;So, I know that the correct layer is being selected and it will print out the said selected layer's OBJECTID.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, as soon as I get into updating the cursor, I'll receive an error message saying:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;line 29, in onClick
    with arcpy.da.UpdateCursor(sample,['block', 'sub_code', 'blockanno']) as blockanno:
RuntimeError: 'in_table' is not a table or a featureclass&lt;/LI-CODE&gt;&lt;P&gt;Any suggestions on how to fix this or get around the error in order to run the nested if statements?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my current script:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import pythonaddins

class ButtonClass1(object):
    """Implementation for Test2_addin.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        ## if editing:
		## elif msg -- put on edit  and then exit
		mxd = arcpy.mapping.MapDocument('current')
		df = mxd.activeDataFrame
		Fields = ["block", "sub_code", "blockanno"]

		lyr = arcpy.mapping.ListLayers(mxd)[1]
		pythonaddins.MessageBox("layer is {}".format(lyr), "Message Box", 0)
		selected = ''
			
		sample = lyr.getSelectionSet()
		for row in sample:
			selected = selected + ', ' + str(row)
		
		pythonaddins.MessageBox("selected =" + str(selected), "Message Box", 0)
			
		with arcpy.da.UpdateCursor(sample,['block', 'sub_code', 'blockanno']) as blockanno:
			for row in blockanno:
				if row[1] != '0000' and row[1] != '0780':
					if row[0][0:3].isdigit():
						row[2] = str(row[0][0:3].lstrip('0'))
					elif row[0].isalpha():
						if row[0][0:2] == '00':
							row[2] = str(row[0][0:].strip('0'))
			# pythonaddins.MessageBox("blockanno is {}".format(row[2]), "Message Box", 0)
			blockanno.updateRow(row)&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 17 May 2021 14:36:54 GMT</pubDate>
    <dc:creator>kad37_pns</dc:creator>
    <dc:date>2021-05-17T14:36:54Z</dc:date>
    <item>
      <title>RuntimeError: 'in_table' is not a table or a featureclass</title>
      <link>https://community.esri.com/t5/python-questions/runtimeerror-in-table-is-not-a-table-or-a/m-p/1058526#M61152</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I've been working on a script that will take a group of manually selected features and utilize UpdateCursor to update a field based on three other columns. As of right now, I'm programming it so that messages appear to provide proof of concept.&lt;STRONG&gt; The goal of this is to automate what was a field calculation process into a python add in button.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;So, I know that the correct layer is being selected and it will print out the said selected layer's OBJECTID.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, as soon as I get into updating the cursor, I'll receive an error message saying:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;line 29, in onClick
    with arcpy.da.UpdateCursor(sample,['block', 'sub_code', 'blockanno']) as blockanno:
RuntimeError: 'in_table' is not a table or a featureclass&lt;/LI-CODE&gt;&lt;P&gt;Any suggestions on how to fix this or get around the error in order to run the nested if statements?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my current script:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import pythonaddins

class ButtonClass1(object):
    """Implementation for Test2_addin.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        ## if editing:
		## elif msg -- put on edit  and then exit
		mxd = arcpy.mapping.MapDocument('current')
		df = mxd.activeDataFrame
		Fields = ["block", "sub_code", "blockanno"]

		lyr = arcpy.mapping.ListLayers(mxd)[1]
		pythonaddins.MessageBox("layer is {}".format(lyr), "Message Box", 0)
		selected = ''
			
		sample = lyr.getSelectionSet()
		for row in sample:
			selected = selected + ', ' + str(row)
		
		pythonaddins.MessageBox("selected =" + str(selected), "Message Box", 0)
			
		with arcpy.da.UpdateCursor(sample,['block', 'sub_code', 'blockanno']) as blockanno:
			for row in blockanno:
				if row[1] != '0000' and row[1] != '0780':
					if row[0][0:3].isdigit():
						row[2] = str(row[0][0:3].lstrip('0'))
					elif row[0].isalpha():
						if row[0][0:2] == '00':
							row[2] = str(row[0][0:].strip('0'))
			# pythonaddins.MessageBox("blockanno is {}".format(row[2]), "Message Box", 0)
			blockanno.updateRow(row)&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 17 May 2021 14:36:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtimeerror-in-table-is-not-a-table-or-a/m-p/1058526#M61152</guid>
      <dc:creator>kad37_pns</dc:creator>
      <dc:date>2021-05-17T14:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: RuntimeError: 'in_table' is not a table or a featureclass</title>
      <link>https://community.esri.com/t5/python-questions/runtimeerror-in-table-is-not-a-table-or-a/m-p/1058544#M61154</link>
      <description>&lt;P&gt;Your sample variable is just a list of objectid's (being returned from the getSelectionSet() method) and is not a table that is usable by the cursor.&amp;nbsp; I think that you will have to iterate over those ObjectID's, create a where clause for the cursor.&amp;nbsp; You can do them all at once, or one at a time. You will also have to pass in the featureclass that you are updating to where the 'sample' currently is.&amp;nbsp; Instead of the for row in sample line you got there, try something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for oid in sample:
    whereclause = f'''OBJECTID = {oid}'''
    with arcpy.da.UpdateCursor('YOUR FC HERE', ['block', 'sub_code', 'blockanno'], whereclause) as uCur:
        for row in uCur:
            ...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;PS, Id also change the blockanno cursor to uCur or something to differentiate it from the blockanno field.&lt;/P&gt;</description>
      <pubDate>Mon, 17 May 2021 14:52:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtimeerror-in-table-is-not-a-table-or-a/m-p/1058544#M61154</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-05-17T14:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: RuntimeError: 'in_table' is not a table or a featureclass</title>
      <link>https://community.esri.com/t5/python-questions/runtimeerror-in-table-is-not-a-table-or-a/m-p/1058573#M61156</link>
      <description>&lt;P&gt;not sure, but try just calling the layer by its name. as ther is selection, update cursor will work on selection. So replace&amp;nbsp; line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sample = lyr.getSelectionSet()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;with line&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sample = lyr.name&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 May 2021 15:42:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtimeerror-in-table-is-not-a-table-or-a/m-p/1058573#M61156</guid>
      <dc:creator>Tomasz_Tarchalski</dc:creator>
      <dc:date>2021-05-17T15:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: RuntimeError: 'in_table' is not a table or a featureclass</title>
      <link>https://community.esri.com/t5/python-questions/runtimeerror-in-table-is-not-a-table-or-a/m-p/1058580#M61157</link>
      <description>&lt;P&gt;Could you explain a bit more on what the line:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt; whereclause = f'''OBJECTID = {oid}'''&lt;/LI-CODE&gt;&lt;P&gt;Is supposed to accomplish? I've been scratching my head over that. Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 May 2021 15:53:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtimeerror-in-table-is-not-a-table-or-a/m-p/1058580#M61157</guid>
      <dc:creator>kad37_pns</dc:creator>
      <dc:date>2021-05-17T15:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: RuntimeError: 'in_table' is not a table or a featureclass</title>
      <link>https://community.esri.com/t5/python-questions/runtimeerror-in-table-is-not-a-table-or-a/m-p/1058582#M61158</link>
      <description>&lt;P&gt;Yeah, unfortunately all that produces is the actual name of the layer, not what's within the layer which is what I'm trying to calculate from. Thanks, though!&lt;/P&gt;</description>
      <pubDate>Mon, 17 May 2021 15:54:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtimeerror-in-table-is-not-a-table-or-a/m-p/1058582#M61158</guid>
      <dc:creator>kad37_pns</dc:creator>
      <dc:date>2021-05-17T15:54:35Z</dc:date>
    </item>
    <item>
      <title>Re: RuntimeError: 'in_table' is not a table or a featureclass</title>
      <link>https://community.esri.com/t5/python-questions/runtimeerror-in-table-is-not-a-table-or-a/m-p/1058588#M61160</link>
      <description>&lt;P&gt;Its creating a sql query string to select the feature by matching the OBJECTID to the oid.&amp;nbsp; It can also be written as 'OBJECTID = {}'.format(oid) or like 'OBJECTID = ' + str(oid).&amp;nbsp; It is then used in the cursor to filter the selection to the matching feature(s).&lt;/P&gt;</description>
      <pubDate>Mon, 17 May 2021 16:05:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtimeerror-in-table-is-not-a-table-or-a/m-p/1058588#M61160</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-05-17T16:05:40Z</dc:date>
    </item>
    <item>
      <title>Re: RuntimeError: 'in_table' is not a table or a featureclass</title>
      <link>https://community.esri.com/t5/python-questions/runtimeerror-in-table-is-not-a-table-or-a/m-p/1058602#M61161</link>
      <description>&lt;P&gt;You may be able to just use the lyr variable in place of 'sample' in your updatecursor since it's pointing to the featureclass, replacing the 'your FC here' from my example above, and maybe skipping the iteration over the 'sample' list of objectids.&lt;/P&gt;</description>
      <pubDate>Mon, 17 May 2021 16:31:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtimeerror-in-table-is-not-a-table-or-a/m-p/1058602#M61161</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-05-17T16:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: RuntimeError: 'in_table' is not a table or a featureclass</title>
      <link>https://community.esri.com/t5/python-questions/runtimeerror-in-table-is-not-a-table-or-a/m-p/1058606#M61162</link>
      <description>&lt;P&gt;I'm with Jeff on this.&lt;/P&gt;</description>
      <pubDate>Mon, 17 May 2021 16:34:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtimeerror-in-table-is-not-a-table-or-a/m-p/1058606#M61162</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2021-05-17T16:34:29Z</dc:date>
    </item>
    <item>
      <title>Re: RuntimeError: 'in_table' is not a table or a featureclass</title>
      <link>https://community.esri.com/t5/python-questions/runtimeerror-in-table-is-not-a-table-or-a/m-p/1059956#M61179</link>
      <description>&lt;P&gt;Discovered that my issue was in how I was formatting my rows. Below is a piece of code that worked for me:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.UpdateCursor(lyr, Fields) as uCur:
			print("got here")
			for row in uCur:
				row[4] = self.block_anno_calc(row[0], row[1], row[2], row[3])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help, y'all! Made some good headway on this project.&lt;/P&gt;</description>
      <pubDate>Thu, 20 May 2021 14:42:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/runtimeerror-in-table-is-not-a-table-or-a/m-p/1059956#M61179</guid>
      <dc:creator>kad37_pns</dc:creator>
      <dc:date>2021-05-20T14:42:53Z</dc:date>
    </item>
  </channel>
</rss>

