arcpy.mapping.tableView.replaceDataSource and multiple databases

589
1
02-13-2013 09:12 AM
EricPfirman
New Contributor III
We are migrating our geodatabase and multiple business databases to a new server.I am trying to use arcpy.mapping.tableView.replaceDataSource to migrate the OLEDB tables in our MXDs to the new server. The tables may come from any one of the databases. Is there a way to identify which database the table is in? Is there a way to change the server and keep the database the same?
Tags (2)
0 Kudos
1 Reply
by Anonymous User
Not applicable
Yes, you can use the layer properties (workspacePath) to print the workspace.

import arcpy
from arcpy import mapping as m

mapdoc = r'G:\Map_Documents\Walkin_requests\Customer_map.mxd'

mxd = m.MapDocument(mapdoc)
for lyr in m.ListLayers(mxd):
    if lyr.supports('DATASOURCE'):
        print '%s:  %s' %(lyr.name,lyr.workspacePath)



Next, you can use the find and replace workspace paths to change your workspaces for each table.

for example:

old = r'G:\Data\Geodatabase\Cedar_County.mdb' # old worspace 1
new = r'G:\Data\Geodatabase\Cedar_County.gdb' # new workspace 1

if lyr.workspacePath == r'G:\Some\path\gdb':
    mxd.replaceWorkspaces(old,'ACCESS_WORKSPACE',new,'FILEGDB_WORKSPACE')

0 Kudos