enter image description hereI found the code that works to change the layers in my mxd from one SDE workspace to the other SDE worksspace. The script runs, but does not change the tables to the new SDE workspace. I replaced lyr with Table, but can't seem to get it to work. Once I get the table data source script to update I will put it into code that loops through MXD files in a specified folder and updates any GDSERVER data connections to point to GDTEST using the assigned connection properties. I am new to this and could use some help please :)

The error msg I get is. Traceback (most recent call last): File "C:\Users\ferencek\Desktop\TEST1.py", line 4, in for Table in arcpy.mapping.ListTables(mxd): AttributeError: 'module' object has no attribute 'ListTables'

import arcpy;

mxd = arcpy.mapping.MapDocument(r"N:\\5-Processes\\Resources\\DynamicData\\SourceMXD\\Copies for GDTEST\\Test\\Data_CCTV.mxd");
for Table in arcpy.mapping.ListTables(mxd):
if Table.supports("DATASOURCE"):Table.replaceDataSource("C:\\Users\\ferencek\\AppData\\Roaming\\ESRI\\Desktop10.2\\ArcCatalog\\sde_appreader (SDE_LIVE) on GDTEST.sde", "SDE_WORKSPACE", Table.datasetName, False)

mxd.saveACopy(r"N:\\5-Processes\\Resources\\DynamicData\\SourceMXD\\Copies for GDTEST\\Test\\CopyData_CCTV.mxd");
del mxd

2 Answers 2


You've got a few issues here. For one, there's no "ListTables" method in arcpy.mapping. There's arcpy.mapping.ListLayers and arcpy.mapping.ListTableViews? I've cleaned up the code a bit.

# generally - don't end lines with semicolon in python
import arcpy 

mxd = arcpy.mapping.MapDocument(insert_path_here)
tables = arcpy.mapping.ListTableViews(mxd)
for t in tables:
    if t.supports("DATASOURCE"):
        t.replaceDataSource(connection_path_here, "SDE_WORKSPACE", t.datasetName, False)
  • Thanks for your response. I tired your code but got this error and am not sure what it means. Traceback (most recent call last): File "C:\Users\ferencek\Desktop\TEST1.py", line 6, in <module> if t.supports("DATASOURCE"): AttributeError: 'TableView' object has no attribute 'supports' Commented Jan 22, 2015 at 16:20
  • I could be wrong, but I think that line of code is unnecessary. It checks if a table has the property "DATASOURCE", but I would think all tables returned from ListTableViews would. Try the code without the if t.supports("DATASOURCE"): line. Commented Jan 22, 2015 at 16:49

This is the code that works :)

import arcpy 

mxd = arcpy.mapping.MapDocument(r"N:\\5-Processes\\Resources\\DynamicData\\SourceMXD\\Copies for GDTEST\\Test\\Data_CCTV.mxd")
tables = arcpy.mapping.ListTableViews(mxd)
for t in tables:
        t.replaceDataSource("C:\\Users\\ferencek\\AppData\\Roaming\\ESRI\\Desktop10.2\\ArcCatalog\\sde_appreader (SDE_LIVE) on GDTEST.sde", "SDE_WORKSPACE", t.datasetName, False)
 mxd.saveACopy(r"N:\\5-Processes\\Resources\\DynamicData\\SourceMXD\\Copies for GDTEST\\Test\\CopyData_CCTV.mxd")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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