4

I'm attempting to replace the data source of a unsourced layer with a mxd. The issue I'm having is that the Featureclass "APPL" is contained within a Feature Dataset. When the feature class is outside of the data set the code below works perfectly.

   workspace = output + "\\PlanningSession.gdb\\DIDs" ## Dataset

   lyr = arcpy.mapping.ListLayers(mxd,"DAB_APPL", df)[0]
   lyr.replaceDataSource(workspace, "FILEGDB_WORKSPACE", "APPL")

The error received can be found below:

    Traceback (most recent call last):
      File "Q:\Admin\Python_Scripts\Tools\PlanningSession\Script\PlanningSession.py", line 356, in <module>
        lyr.replaceDataSource(workspace, "FILEGDB_WORKSPACE", "APPL")
      File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\utils.py", line 182, in fn_
        return fn(*args, **kw)
      File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\_mapping.py", line 681, in replaceDataSource
        return convertArcObjectToPythonObject(self._arc_object.replaceDataSource(*gp_fixargs((workspace_path, workspace_type, dataset_name, validate),True)))
    ValueError: Layer: Unexpected error

    Failed to execute (PlanningSession). 
4

I have found the solution to my problem. Instead of referencing the dataset within the geodatabase, simply reference the geodatabase.

For example:

    # workspace = output + "\\PlanningSession.gdb\\DIDs" ## Referencing the Feature Dataset
    workspace = output + "\\PlanningSession.gdb" ## Referencing the GDB

    lyr = arcpy.mapping.ListLayers(mxd,"DAB_APPL", df)[0]
    lyr.replaceDataSource(workspace, "FILEGDB_WORKSPACE", "APPL")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.