import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] # loop through layers to get layer names, replace layer file fcList = [[roads,r'roads.lyr path'], [rivers,r'rivers.lyr path'], [buildings,r'buildings.lyr path']] for fc in fcList: fc = arcpy.mapping.ListLayers(mxd, fc[0],df)[0] updateLayer = arcpy.mapping.ListLayers(mxd,fc,df)[0] sourceLayer = arcpy.mapping.Layer(fc[1]) arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, True) # refresh view and table of contents, save changes to mxd arcpy.RefreshActiveView() arcpy.RefreshTOC() mxd.save() del sourceLayer, mxd
fcDict = {roads:r'roads.lyr path', rivers:r'rivers.lyr path', buildings:r'buildings.lyr path'} for fc,lyr in fcDict.iteritems(): fc = arcpy.mapping.ListLayers(mxd, fc,df)[0] updateLayer = arcpy.mapping.ListLayers(mxd,fc,df)[0] sourceLayer = arcpy.mapping.Layer(lyr) arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, True)
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.