Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import xlrd, arcpy, os
- mxd_path = r'C:tempChapters'
- d = {}
- wb = xlrd.open_workbook('U:GISChevron_LokernProjectsFigures_Update_2014Lokern_Source_Paths_KL.xls')
- sh = wb.sheet_by_index(0)
- for i in range(293):
- cell_value_class = sh.cell(i,0).value
- cell_value_id = sh.cell(i,1).value
- d[cell_value_class] = cell_value_id
- for dirpath, dirnames, filenames in os.walk(mxd_path):
- for filename in filenames:
- fullPath = os.path.join(dirpath, filename)
- if filename[-4:] == ".mxd":
- mxd = arcpy.mapping.MapDocument(fullPath)
- print filename
- for lyr in arcpy.mapping.ListLayers(mxd):
- if lyr.supports("DATASOURCE"):
- #print lyr.datasetName
- for k,v in d.iteritems():
- #print k,v
- k_path, k_name = os.path.split(k)
- v_path, v_name = os.path.split(v)
- if lyr.dataSource == k and k != v:
- #print 'KEY:',k,'VAL:',v, 'NAME:',v_name
- try:
- print 'trying to change data source for',lyr.dataSource
- lyr.replaceDataSource(v_path,'FILEGDB_WORKSPACE',v_name,True)
- except Exception as e:
- print 'can't replace',lyr.dataSource, e
- try:
- print 'trying to change data source for',lyr.dataSource
- lyr.replaceDataSource(v_path,'RASTER_WORKSPACE',v_name,True)
- except Exception as e:
- print 'still can't replace',lyr.dataSource, e
- try:
- print 'trying to change data source for',lyr.dataSource
- lyr.replaceDataSource(v_path,'SHAPEFILE_WORKSPACE',v_name,True)
- except Exception as e:
- print 'still can't replace',lyr.dataSource, e
- try:
- print 'trying to change data source for',lyr.dataSource
- lyr.findAndReplaceWorkspacePath(k_path,v_path)
- except Exception as e:
- print 'can't replace workspace path for',lyr.datasetName, e
- mxd.relativePaths = 'True'
- mxd.save()
- del mxd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement