AnsweredAssumed Answered

Adding Layer from Pywin to open mxd using Python

Question asked by TobyJacobs on Oct 15, 2015
Latest reply on Oct 19, 2015 by FGibson-esristaff

Trying to automate some editing tasks and then exporting the files to pdf's. I'm getting stuck with loading the layers into ArcMap.

 

I can do it in the Python window using the standard:

arcpy.mapping.MapDocument("CURRENT")

df = arcpy.mapping.ListDataFrames(mxd,"*")[0]

newlayer = arcpy.mapping.Layer(r"H:\2.shp")

arcpy.mapping.AddLayer(df, newlayer,"TOP")

 

but when I try to do it by referencing the mxd path instead of "CURRENT" in Pywin or a script tool (see below), it runs through but doesn't actually load the shapefile onto the map:

arcpy.mapping.MapDocument(r"H:\map2.mxd")

df = arcpy.mapping.ListDataFrames(mxd,"*")[0]

newlayer = arcpy.mapping.Layer(r"H:\2.shp")

arcpy.mapping.AddLayer(df, newlayer,"TOP")

 

I've tried the second code in the Arc Python window, and it doesn't work there either. Any ideas? I'm sure it's a simple issue...

 

Thanks!

Outcomes