AnsweredAssumed Answered

Replace Data Sources from shapefile to feature dataset feature class in an mxd using

Question asked by gabrisch on Oct 3, 2011
Latest reply on Oct 5, 2011 by jbarrette-esristaff
We have migrated a bulk of our GIS data from shapefiles into feature classes within feature datasets (ArcGIS-file geodatabase-feature datasets).
I am trying to develop a Python script to automatically replace the most popular datasets in an mxd with the paths to the new data. 

My problem is that both the data model (shapefile to feature dataset feature class) has changed, and the feature class name has changed.

The replaceDataSource() and replaceWorkspacePaths() methods do not have parameter for connecting to feature datasets.

The code posted below works if I move my feature class out of the feature dataset within the file geodatabase (meaning the syntax is good). Still, how to I set the replaceDataSource to a feature data set?

    import arcpy.mapping, os, sys, string, traceback
    mxd = arcpy.mapping.MapDocument("CURRENT")
    for dataframe in arcpy.mapping.ListDataFrames(mxd):
        BrokenLinkList = arcpy.mapping.ListBrokenDataSources(dataframe)      
        for item in  BrokenLinkList:
            print item.datasetName
            if item.datasetName == r"LummiReservationFullBoundary":
                print "droppin' in"
                #The path to the new directory...
                newWorkspace = r"Z:\Data\Boundaries\Administrative\Lummi.gdb\TribalBoundaries"
                #The new dataset name...
                datasetName = r"LummiReservation"
                #This should have a "FEATUREDATASET" options to replace FILEGDB_WORKSPACE.
                item.replaceDataSource (newWorkspace, "FILEGDB_WORKSPACE", datasetName, False)
    del mxd
    print "Done"
except arcpy.ExecuteError: 
    msgs = arcpy.GetMessages(2) 
    print msgs
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]
    pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
    msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
    print pymsg + "\n"
    print msgs