I'm trying to add a layer to the current MXD using an arcpy toolbox (.pyt).
When I execute the program it draws the entire layer then immediately dissappears from the TOC which basically returns to the old version of the MXD. Other times it does not draw the layer but still there is not an error message.
Here is the code I'm using for the execute routine as a toolbox:
BTW: This problem was discussed in 10.0 and they said it was fixed in a SP. I think the difference might be that I'm using a toolbox ".pyt" to add the layer.
http://forums.arcgis.com/threads/833...7150#post57150
When I execute the program it draws the entire layer then immediately dissappears from the TOC which basically returns to the old version of the MXD. Other times it does not draw the layer but still there is not an error message.
Here is the code I'm using for the execute routine as a toolbox:
Code:
def __init__(self):
self.label = "Add Layer"
self.description = "Adds a layer to ArcMap"
self.canRunInBackground = False
########################
def execute(self, parameters, messages):
arcpy.MakeFeatureLayer_management("C:\BILL\CB_TEMP\cb.shp", "LAYER")
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
addLayer = arcpy.mapping.Layer("LAYER")
arcpy.mapping.AddLayer(df, addLayer, "TOP")
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
# del mxd
http://forums.arcgis.com/threads/833...7150#post57150