robertf

Replacedatasource not working with a shapefile

Discussion created by robertf on Aug 14, 2012
Latest reply on Aug 15, 2012 by curtvprice
And I can't for the life of me figure out why this isn't working.  It worked fine in a previous script when I had to resource multiple grid files in a single data frame but I can't get this one, tiny, simple, shapefile to re-source to a new workspace and name.  The workspace and name would be managed by user input but at this time I've got it hard coded.  Does anyone have any idea why this isn't working?  Script and the error I get pasted below. 

Rob

*********** THE SCRIPT ************************************************
#Return a list of all the mxds in the input folder
Inputmxds = os.listdir(INPUT_DIR)
for a in Inputmxds:
        if "Figure1" in a:
                # Open the mxd
                Themxd = arcpy.mapping.MapDocument(INPUT_DIR + "\\" + a)
               
                # Set variables to the project, turbines               
                MainDF = arcpy.mapping.ListDataFrames(Themxd, "Main View")[0]
                for feat_lay in arcpy.mapping.ListLayers(Themxd, "", MainDF):
                        #print feat_lay
                        if feat_lay.name.upper() == "PROJECT_AREA":
                                TheWRA = feat_lay
                                print TheWRA
                                #Resource the project boundary to the input wra
                                TheWRA.replaceDataSource("C:\Python_Avian_Reports", "SHAPEFILE_WORKSPACE", "Project_Boundary.shp")


*********** THE ERROR MESSAGE ************************************************
Traceback (most recent call last):
  File "C:\Python26\ArcGIS10.0\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 312, in RunScript
    exec codeObject in __main__.__dict__
  File "P:\GIS_MANAGEMENT\ESRI_Related\Library_Python\Arc10\Avian_Report_Figures\AvianReportFigures_Hardcoded.py", line 39, in <module>
    TheWRA.replaceDataSource("C:\Python_Avian_Reports", "SHAPEFILE_WORKSPACE", "Project_Boundary.shp")
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\utils.py", line 181, in fn_
    return fn(*args, **kw)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\_mapping.py", line 585, in replaceDataSource
    return convertArcObjectToPythonObject(self._arc_object.replaceDataSource(*gp_fixargs((workspace_path, workspace_type, dataset_name, validate), True)))
ValueError: Layer: Unexpected error

Outcomes