arcpy.ma addTable method of Map class doesn't work for .dbf table

533
4
12-11-2018 11:29 AM
SheilaChurchill1
New Contributor II

ArcGIS Pro 2.2

Python 3.6

I am trying to add a .dbf table from disk to an existing map in an ArcGIS Pro project. The addTable method of the Map class works with a file geodatabase table, but does not work with a .dbf table. I created a simple map and script tool to test this, and a python script tool with a single input parameter of type "Table"

Here is the python script:

#script tool for testing addTable
theTable = arcpy.GetParameterAsText(0)

theProject = arcpy.mp.ArcGISProject("CURRENT")

arcpy.AddMessage(theTable)
theMap = theProject.listMaps()[0]    

#now add table to map - use table function of mp to create a table object
# then use addTable method of map to add the table
theSumTab = arcpy.mp.Table(theTable)
theMap.addTable(theSumTab)

When I test this script tool by navigating to a file geodatabase table everything works:

When I test this script tool by navigating to a .dbf table it fails:

Do I need to do something differently in order for this to work with a .dbf table? Or does addTable just not have that functionality. It doesn't specify that in the help: http://pro.arcgis.com/en/pro-app/arcpy/mapping/map-class.htm 

Thanks for any input.

Sheila Churchill

0 Kudos
4 Replies
DanPatterson_Retired
MVP Esteemed Contributor

you might want to check for the dbase instance

dBase Table properties—ArcPy Functions | ArcGIS Desktop 

copy rows supports dbase

Copy Rows—Data Management toolbox | ArcGIS Desktop and

tabletotable

Table To Table—Conversion toolbox | ArcGIS Desktop 

List tables provides the list

Map—ArcPy | ArcGIS Desktop 

if they exist in the map

Table—ArcPy | ArcGIS Desktop 

So I would make a featureclass table from the dbf if you want shorten what needs to be cheked, but the dbase table properties allows you to check for them

0 Kudos
SheilaChurchill1
New Contributor II

Thanks for replying Dan. I do not want to have to convert the .dbf table to a file geodatabase table, which is what copy rows or table to table does. If the .dbf table has already been added to the map manually, listTables will return it in the list.  I did try your suggestion of the Describe function to look at the table properties. However, that made me realize my script is failing when I use the Table function of arcpy.ma, not the addTable method of the map. So I am not able to use the Table function of arcpy.ma to create a table object from the string holding the table data source  as it outlines in the help ( Table—ArcPy | ArcGIS Desktop ). Perhaps the string that represents the data source of the .dbf table needs to be in a different format - I have encountered issues with coverages and ArcGIS Pro, maybe there are issues with dbf tables associated with shapefiles too.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

Worth a check... the describe property for the dbf is quite specific.  The string representing the dbf would just have to include its file extension, it wouldn't matter if it was part of a shapefile

0 Kudos
MichelMelanson1
New Contributor

I was having the same issue while trying to add a dbf table using the addTable method (m.addTable(tbl)). Using the addDataFromPath (data_path) method worked for me. https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/map-class.htm : addDataFromPath. 

0 Kudos