I'm trying to change the workspace path of a query layer using the code below and it always breaks. The layer is connected to a view in an Oracle Spatial 10g database. The database is SDE enabled although since it is a query layer SDE knows nothing of it.
The tables which python is changing the workspace path of are actually views which is why they are query layers. The problem I'm experiencing is that the layers are broken after the code is run on them. It seems the workspace path is changed correctly but the "Table Type" is (null) and it has lost its Object-ID Field mapping. Does anyone know why it corrupts the layer like this when I run the code below?
import arcpy, os # Globals process_folder = r"C:\Users\tfronal\mxds" dev_workspacePath = r"C:\Users\tfronal\connections\ORACLEDEV_SDVIEWER.sde" change_flag = False for filename in os.listdir(process_folder): fullpath = os.path.join(process_folder, filename) if os.path.isfile(fullpath): basename, extension = os.path.splitext(fullpath) if extension.lower() == ".mxd": change_flag =False print "--------------------------------------------------" print "Opening MXD:" + fullpath mxd = arcpy.mapping.MapDocument(fullpath) for tbl in arcpy.mapping.ListTableViews(mxd): if "oraclestage" in tbl.workspacePath.lower(): tbl.findAndReplaceWorkspacePath(tbl.workspacePath, dev_workspacePath, False) print "New workspace path: " + tbl.workspacePath change_flag = True if change_flag == True: mxd.save() print "mxd saved." del mxd print "Finished"
EDIT: Adding some additional information as per comments request. This code is meant to be used to migrate mxd/s between staging and development environments and so on. The change of workspace(.SDE file used) will change the database, username and password. The MXD is saved from ArcMap 10.2.2.