0

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
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 2, 2018 at 19:50
3
  • 1
    it looks like you're just assigning the actual arcpy.maketableview to a variable you're not executing the function so it cant add the table view if it doesn't exist. Commented Nov 2, 2018 at 23:11
  • I agree, cList is probably a result object. Try changing arcpy.mapping.AddTableView(df, cList) to the actual layer name: arcpy.mapping.AddTableView(df, "cList") Commented Nov 3, 2018 at 9:17
  • @BERA I changed the code as you suggested but I'm still getting the same error. Commented Nov 5, 2018 at 19:42

1 Answer 1

1

Instead of:

# 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)

try this:

# create tableview
tblView = arcpy.mapping.TableView("CensusTract")
# add tableview to dataframe
mxd = arcpy.mapping.MapDocument(r"C:\TableView.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
arcpy.mapping.AddTableView(df,tblView)

I used the AddTableView help to come up with the above untested code.

answered Sep 26, 2019 at 7:06

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.