Hi Scott,
Thank you for the response!
I managed to modify the code that I posted to:
mxd = arcpy.mapping.MapDocument(r"C:/gis/gis540/Project/test.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "")[0]
addLayer1 = arcpy.mapping.Layer(r"C:/gis/gis540/Project/firehydrants/add6.shp")
arcpy.mapping.AddLayer(df, addLayer1)
mxd.save()
del mxd, addLayer
You mentioned that AddLayer should add a .lyr file, but adding a .shp file seems to work. I'm not exactly sure why. Possibly it's a quirk?
I have tried to expand this code to:
mxd = arcpy.mapping.MapDocument(r"C:/gis/gis540/Project/test.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "")[0]
addLayer1 = arcpy.mapping.Layer(r"test.lyr")
arcpy.mapping.AddLayer(df, addLayer1)
targetGroupLayer = arcpy.mapping.ListLayers(mxd, addLayer1, df)[0]
addLayer2 = arcpy.mapping.Layer(r"C:/gis/gis540/Project/firehydrants/add7.shp")
print df, targetGroupLayer, addLayer2
arcpy.mapping.AddLayerToGroup(df, targetGroupLayer, addLayer2) #, "BOTTOM")
mxd.save()
del mxd, addLayer1, addLayer2
Where test.lyr is meant to be an empty Layer Group which will be populated by add7.shp However, when I use test.lyr I end up getting "ValueError: Object: CreateObject Layer invalid data source" then when I put an actual file in there such as "C:/gis/gis540/Project/firehydrants/add6.shp" I end up with an "AssertionError."
To be honest, I'm somewhat new to programming Python using arcpy. But, I would have thought there is a way to create a blank group layer and then add other layers to it.
Thanks again,
John