mzcoyle;186689 wrote:
Posting your full code may help, I suspect a problem with your file_name variable, as well as the specific errors you are receiving. The code you posted works fine for me, modified thusly.
It's a bit clunky. Some of the information is sensitive, so here is the best I can do:(I just made things a bit more generic)
import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd, "Plume_Layer*"):
if lyr.supports("DATASOURCE"):
lyr_name = lyr.name
name_parts = lyr_name.split("_")
var1 = name_parts[2]
var2 = name_parts[5]
years = int(name_parts[7])
var3 = name_parts[9].lstrip("L")
if years <= 5:
months = "0" + str(years*12)
elif years == 48:
months = "313"
elif years == 76:
months = "313"
else:
months = str(years*12)
if years <> 48:
days = years * 365
days = str(days) + ".00"
else:
days = "17699.84"
file_name = var1 + "_" + "BC" + "_" + "SP0" + months + "_" + "L000" + var3 + "_T" + days + ".ASC"
lyr.replaceDataSource(r"C:\Folder", "NONE", file_name)
del mxd
So a sample layer in the map is just a bunch of variables separated by underscores, like:"XXX_XXX_[var1]_XXX_XXX_[var2]_XXX_[years]_XXX_[var3]"And a file name in the folder is like this:"[var1]_BC_SP0[months]_L000[var3]_T[days].ASC"When you tried the code you had, did you run it on multiple files? Mine runs, it just links everything to the same file (which is incorrect obviously).