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
  • 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. – NULL.Dude Nov 2 '18 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") – BERA Nov 3 '18 at 9:17
  • @BERA I changed the code as you suggested but I'm still getting the same error. – geoJshaun Nov 5 '18 at 19:42
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.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.