newell.kate

Replace Data Source only works for first Instance?

Discussion created by newell.kate on Dec 2, 2011
Latest reply on Dec 13, 2011 by sdpawlak
I have an mxd with A LOT of feature classes in it...some of the feature classes have multiple instances/occurances in my mxd (because they have specific DefQueries).  I want to Replace the Data Source to our new SDE location.  In my "dumbed" down script below, I am only trying to change the "Neighborhoods" feature class, which occurs twice in my mxd.  The script runs with no errors and prints out my print statement twice, making it seem like it replaced the Data source for both instances...however when I open the mxd, only the first instance has been replaced and the second instance is still broken.  If I close ArcMap and run the script again, it will then update the second instance...how do I do this in my script sot that it replaces both instances and not the first one it comes across?  Seems simple, but I can't seem to figure it out! (have also included jpg screenshot of my script if that makes it easier to view). Thanks for any help

import arcpy, os
mxd = arcpy.mapping.MapDocument(r"N:\ArcShared\planning\Neighborhood_Maps\Master_MXDs\Version10\Barkley.mxd")

for brkLyr in arcpy.mapping.ListBrokenDataSources(mxd):
    if brkLyr.dataSource == "C:\Documents and Settings\cjb\Application Data\ESRI\ArcCatalog\PUBLIC Connection to Columbia.sde\COBGIS.Planning\COBGIS.Neighborhood":
        brkLyr.replaceDataSource(r"N:\ArcGIS\Connections\Richmond_sdepub.sde", "SDE_WORKSPACE", "sdepub.COBGIS.plan_Neighborhoods", "")
        print brkLyr.dataSource
        print "Neighborhoods replaced"
        mxd.save()
del mxd

Outcomes