Good day all,
I am trying to automate a process at my work, the script will start by updating the data source for a layer file (.lyr) found at the top of the contents pane in a map document.
The original data source for the layer file is a shapefile and I am trying to update it to a new shapefile found in a workspace/ folder I have assigned the variable "path" to (see screenshot below).
The following screenshot is, from my understanding, a simple way to write the code. I was using the python window in ArcMap for troubleshooting purposes:
As you can see I receive an error message.
I have tried writing this script several different ways, even omitting the map document and pointing straight to the layer file (arcpy.mapping.Layer([path])) but continue to get this error message.
The mapdocument is added ("mxd"), as is the dataframe ("df"), and the layer ("lyr").
Upon reading through past post regarding the .replaceDataSource function, I have seen I am not the first to receive this error message.
I am just starting to write my own scripts and apologize if I reffered to anything incorrectly.
Has anyone figured out how to get past/ correct the error?
Any help with this is greatly appreciated.
Here is the script as I have it written in an IDE, it's not complete but useful for context:
import arcpy, os
#Define variables
mxd = arcpy.mapping.MapDocument(r"D:\Brodie\Projects\2024\2024 IMT Templates\yyyymmdd_XXX###_OPS_TABLOID_LAND.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "")[0]
lyr = arcpy.mapping.ListLayers(mxd, "", df)[0]
path = r"D:\Brodie\Projects\2023\AFFESIncidentData2023\SUD017_2023\IncidentData\\" #Path to new source data
nom = "20230613_1900_SUD017_MAP.shp" #Name of new source data
#Update data source for fire perimeter .lyr
lyr.replaceDataSource(path, "SHAPEFILE_WORKSPACE", nom)
lyr.name = "20230613_1900_SUD017_MAP" #Name of updated layer as it appears in the contents pane
#Save mxd under new name
mxd.saveACopy(r"D:\Brodie\Projects\2023\AFFESIncidentData2023\SUD017_2023\Projects\20230613_1900_SUD017_OPS_TABLOID_LAND.mxd")
print "Script complete"