1

I have a mosaic layer that I want to add to my map in ArcMap. When I add this layer manually (i.e the "Add Data" button), a raster image, a boundary, and a footprint are added to my table of contents. However, when I run the following code, only the raster image is added to my TOC. I have no idea why this happens.

How do I get my code to also add the footprint and boundary to the map?

    import arcpy
    in_workspace = r"C:\Users\Christian\Documents\ArcGIS\Default.gdb"
    in_mosaicdataset_name = "mosaic_file"
    mxd = arcpy.mapping.MapDocument("CURRENT")
    df = arcpy.mapping.ListDataFrames(mxd)[0]
    path_to_layer = in_workspace+"\\"+in_mosaicdataset_name
    layer = arcpy.mapping.Layer(path_to_layer)
    arcpy.mapping.AddLayer(df,layer,"BOTTOM")
0
2

As originally edited into the question by its asker (who has not been on the site for two years):

Michael Miles-Stimson's idea worked. The following code produced the desired result:

    import arcpy
    arcpy.env.workspace = r"C:\Users\Christian\Documents\ArcGIS\Default.gdb"
    in_mosaicdataset_name = "mosaic_file"
    mxd = arcpy.mapping.MapDocument("CURRENT")
    arcpy.MakeMosaicLayer_management(in_mosaicdataset_name,in_mosaicdataset_name+"_layer")
    arcpy.SaveToLayerFile_management(in_mosaicdataset_name+"_layer",in_mosaicdataset_name+"_layer.lyr")
    layer = arcpy.mapping.Layer(in_mosaicdataset_name+"_layer")
    df = arcpy.mapping.ListDataFrames(mxd)[0]
    arcpy.mapping.AddLayer(df,layer,"BOTTOM")

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.