mkoneya

Add Layer to Map on Disk

Discussion created by mkoneya on Mar 20, 2011
Latest reply on Mar 21, 2011 by mkoneya
How do I add a Layer to a Map that is not the "CURRENT" map?

If I run the code below, the layer is added to the map that is open

lyrFile = "F:\COS_agsdata\PrintLayerFiles\Parcels.lyr"
mxd = arcpy.mapping.MapDocument("CURRENT") 
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyr = arcpy.mapping.Layer(lyrFile)
arcpy.mapping.AddLayer(df, lyr) 

If I run this code

mapDoc = "F:\COS_agsdata\PrintedMapDocuments\PythonTest.mxd"
lyrFile = "F:\COS_agsdata\PrintLayerFiles\Parcels.lyr"
mxd = arcpy.mapping.MapDocument(mapDoc) 
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyr = arcpy.mapping.Layer(lyrFile)
arcpy.mapping.AddLayer(df, lyr) 

The map on disk is not updated. 

I tried an mxd.save, but that didn't work.     Do I need to update the document with the newly added layer?

Any assistance would be appreciated.

Thanks,

Mele

Outcomes