Add layer script not working

596
2
02-28-2012 04:47 AM
JustinRay1
Occasional Contributor
Hi,
I am attempting to use an add layer script to add a layer which points to an ArcGIS Server Map Service to the current map document.  If you could tell me why this script is not working I would appreciate it:
try:
    import arcpy
    arcpy.env.workspace = r"Z:\Imagery"
    print workspace
    mxd = arcpy.mapping.MapDocument("CURRENT")
    df = arcpy.mapping.ListDataFrames(mxd,'Layers')[0]
    addLayer = arcpy.mapping.Layer(r"Z:\Imagery\2011VBMP.lyr")
    arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
    arcpy.RefreshActiveView()
    arcpy.RefreshTOC()
    del mxd, addLayer
except:
    print "Error"

Thanks,
Justin
Tags (2)
0 Kudos
2 Replies
MathewCoyle
Frequent Contributor
You can start by removing the print workspace line unless you have that variable set somewhere else.
0 Kudos
JustinRay1
Occasional Contributor
Ah, thank you.  Not sure what I was thinking there.
0 Kudos