rbasaria

python map automation...changing data sources

Discussion created by rbasaria on Apr 11, 2011
Latest reply on Apr 11, 2011 by mzcoyle
Hi every one. My goal with this script is to be able to create new map documents with new sources for specific layers in the MXD. Im not sure what I am missing. So far, the script will create new MXD files with new names, but the sources will not change. Thanks for any help.

import arcpy

mxd = arcpy.mapping.MapDocument("C:/Rafiq_GIS/PYTHONTESTING/2011/2011_CountyComm/Projects/Orange/CommissionerDistricts_01.mxd")

mxd.saveACopy("C:/Rafiq_GIS/PYTHONTESTING/2011/2011_CountyComm/Projects/Orange/CommissionerDistricts_02.mxd")

mxd2 = arcpy.mapping.MapDocument("C:/Rafiq_GIS/PYTHONTESTING/2011/2011_CountyComm/Projects/Orange/CommissionerDistricts_02.mxd")

for lyr in arcpy.mapping.ListLayers(mxd2):
    if lyr.name == "OR_She_Dist1.shp":
        lyr.replaceDataSource("C:/Rafiq_GIS/PYTHONTESTING/2011/2011_CountyComm/Data/Orange/OR_She_Dist2.shp")
    if lyr.name == "OR_ADA_Dist1.shp":
        lyr.replaceDataSource("C:/Rafiq_GIS/PYTHONTESTING/2011/2011_CountyComm/Data/Orange/OR_ADA_Dist2.shp")
    if lyr.name == "OR_Rts_Dist1.shp":
        lyr.replaceDataSource("C:/Rafiq_GIS/PYTHONTESTING/2011/2011_CountyComm/Data/Orange/OR_Rts_Dist2.shp")
    if lyr.name == "CountyCommission_TriCounty":
        lyr.definitionQuery = '"DISTRICT" = \'2\' AND "COUNTY" = \'ORANGE\''

mxd2.save()

Outcomes