This is my first time using this site and I'm a bit new to ArcPy. I've looked around for a while but couldn't quite find the answer I was looking for. I have many folders with georeferenced topos in JPEG format and I'm trying to use a for loop to add each one to an mxd one at a time. Here's my code:
import arcpy arcpy.env.workspace = "C:\folder path" mxd = arcpy.mapping.MapDocument("C:\file path.mxd") df = arcpy.mapping.ListDataFrames(mxd,"*") path = "C:\file path\\" rasterList = arcpy.ListRasters() for jpg in rasterList: path += str(jpg) lyr = arcpy.mapping.Layer(path) arcpy.mapping.AddLayer(df, lyr, "TOP") arcpy.RefreshActiveView() arcpy.RefreshTOC()
The path string was my way of concatenating each raster list element to the folder path to be passed to arcpy.mapping.Layer() since it accepts a file path - it managed to run without errors but I don't see any changes in my mxd. I assume this is because arcpy.mapping.Layer() accepts a .lyr file only? With this logic I tried using arcpy.MakeRasterLayer_management() within the loop but I got an AssertionError and didn't know what that meant. Anyone know where I went wrong?