ArcGIS Pro 2.2
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")
theMap = theProject.listMaps()
#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)
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.
you might want to check for the dbase instance
copy rows supports dbase
List tables provides the list
if they exist in the map
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
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.
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
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.