I'm trying to create a Python AddIn for ArcMap 10.6 and the first process of the tool will be to add a tableview to a map document. At this point I just want python code to bring up rows from a table specified by a where clause when creating the table view so you can see this tableview in the data view display of the map document.
Here's my code so far:
import arcpy
# construct where clause
val = "\'%2%\'"
f1 = "DIST_NAME"
WC = """{} LIKE {}""".format(f1, val)
# create tableview
cList = arcpy.MakeTableView_management("CensusTract", "cList", WC)
# add tableview to dataframe
mxd = arcpy.mapping.MapDocument(r"C:\TableView.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
arcpy.mapping.AddTableView(df, cList)
And here is the error that I'm getting:
Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\program files (x86)\arcgis\desktop10.6\arcpy\arcpy\utils.py", line 182, in fn_
return fn(*args, **kw)
File "c:\program files (x86)\arcgis\desktop10.6\arcpy\arcpy\mapping.py", line 114, in AddTableView
assert isinstance(add_table, TableView)
AssertionError
cList
is probably a result object. Try changingarcpy.mapping.AddTableView(df, cList)
to the actual layer name:arcpy.mapping.AddTableView(df, "cList")
– BERA Nov 3 '18 at 9:17