Tonyalmeida

Update\change features data source.

Discussion created by Tonyalmeida on Jan 28, 2014
Latest reply on Jan 29, 2014 by Tonyalmeida
I have some layers that i need to change the data source for.

The current script i have gives me the following error. I don't know why.
if anyone would be kind to help me out please?
thanks.


import arcpy
from arcpy import env
from arcpy import mapping

workspace = arcpy.env.workspace =  "C:/GIS/MAPBOOK/Proposed Zoning Book"

arcpy.env.overwriteOutput = True

mxdList = arcpy.ListFiles("*.mxd")

for mxd in mxdList:
    mxd = workspace + "//" + mxd
    for lyr in arcpy.mapping.ListLayers(mxd): 
        if lyr.name == "PROPOSED ZONING":
                lyr.replaceDataSource("C:/Users/t***a/AppData/Roaming/ESRI/Desktop10.1/ArcCatalog/DSD15_SQLEXPRESS.gds/DSD/DSD.DBO.MUNICIPALITY", "SHAPEFILE_WORKSPACE", "DSD.DBO.FUTURE_LAND_USE_ZONING")
    for lyr in arcpy.mapping.ListLayers(mxd): 
        if lyr.name == "CITY LIMITS":
                lyr.replaceDataSource("C:/Users/t***a/AppData/Roaming/ESRI/Desktop10.1/ArcCatalog/DSD15_SQLEXPRESS.gds/TonyOneWay/TonyOneWay.DBO.Canyon_Features", "SHAPEFILE_WORKSPACE", "TonyOneWay.DBO.City_Limits")            
    print "Successfully updated data sources"
    mxd.save()


Error
Traceback (most recent call last):
  File "C:\GIS\Python Scripts\Change Data Source MXD 2.py", line 13, in <module>
    for lyr in arcpy.mapping.ListLayers(mxd):
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_
    return fn(*args, **kw)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\mapping.py", line 1500, in ListLayers
    result = mixins.MapDocumentMixin(map_document_or_layer).listLayers(wildcard, data_frame)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\mixins.py", line 823, in listLayers
    layers = self.layers
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\mixins.py", line 683, in layers
    for frame in reversed(self.dataFrames):
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\mixins.py", line 695, in dataFrames
    return map(convertArcObjectToPythonObject, self.pageLayout.dataFrames)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\mixins.py", line 679, in pageLayout
    return convertArcObjectToPythonObject(self._mxd._arc_object.pageLayout)
AttributeError: 'unicode' object has no attribute '_arc_object'

Outcomes