AnsweredAssumed Answered

How to iterate through tables in an mxd and replace their workspace paths using 10.4 and Python 2.7

Question asked by howeitzer on Oct 8, 2018
Latest reply on Oct 9, 2018 by howeitzer

I am creating a script that walks through folders and scans for mxds. I use a set to get unique data sources and copy the data to a new folder keeping the same data format. I would then like to access the map document and repath all layers and tables to the copied data. I'm struggling to get the tables repathing code to work. In the below example, I have a fGDB table in the mxd and have copied the fGDB that it sits in to a new folder. I would thus like to repath to the table in the copied fGDB.

 

import arcpy, os
mxdrep = arcpy.mapping.MapDocument("CURRENT")
dfsrep = arcpy.mapping.ListDataFrames(mxdrep)

ignoreStringList = ["Vendor", "vendor", ".sde"]
#Target folder containing the copied fGDB
dbFolder = os.path.join(projFolderPath, "Databases")
for dfrep in dfsrep:
tablesRep = arcpy.mapping.ListTableViews(mxdrep, "", dfrep)
for tableRep in tablesRep:
     tablesRep = arcpy.mapping.ListTableViews(mxdrep, "", dfrep)
     tabRepDataSrc = tableRep.dataSource
     tableRepView = arcpy.mapping.TableView(tabRepDataSrc)
     if not any(folders in str(tabRepDataSrc) for folders in ignoreStringList):
          tabDirPath = tableRep.workspacePath
          tabWsPath = os.path.dirname(tabDirPath)
          tableRepView.findAndReplaceWorkspacePath(str(tabWsPath), dbFolder)
          #arcpy.mapping.AddTableView(dfrep, tableRepView)

Outcomes