I have a script that I'm using to generate raster maps and automatically add them to the map display, but when they are added they are sourced to a temporary location. I use the same code for shapefiles and it links to the correct file.
Here's my code:
for fieldName in fieldList.split(';'): if IDW == 'true': # Run IDW outIDW = Idw(inPointFeatures, fieldName, cellSize, power, searchRadius) raster = fieldName + "b_idw.tif" outIDW.save(raster) # Convert raster to layer out_raster = fieldName + "_idw.lyr" display_raster = fieldName + "_idw.lyr" idw_raster = fieldName + "_idw.lyr" arcpy.MakeRasterLayer_management(raster, out_raster) arcpy.SaveToLayerFile_management(out_raster, display_raster, "ABSOLUTE") # Adjust symbology of IDW layer arcpy.ApplySymbologyFromLayer_management(display_raster, idw_symbology) arcpy.SaveToLayerFile_management(display_raster, idw_raster, "ABSOLUTE") # Add layer to map mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "*") addLayer = arcpy.mapping.Layer(idw_raster) arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
The code works properly and adds the map to the display, but it's sourced in this way...
Folder: C:\Users\User\AppData\Local\Temp Raster: x234bc54_d8c9_c34_by1c458
What I need is for the source to point to the original raster tiff or layer where the files are generated, not this temporary folder. Does anyone know how to accomplish this? I've tried using replaceDataSource and replaceWorkspacePaths, but have not succeeded.