matoretta

Raster is still visible after remove from TOC. Why?

Discussion created by matoretta on May 20, 2012
Latest reply on May 22, 2012 by hua17
Hi i use my function to add Raster layer to map. It works fine. but when  i remove this raster from map (TOC) it is still visible in geoprocessing tool. Do anybody know why? is it bug or is it something wrong whit my code?  see attachment. please.  thank a lot.

here is a code:
def AddLayerToMap(inWorkSpace, Name):
    arcpy.MakeRasterLayer_management(inWorkSpace + "\\" + Name, Name)
    lyr_file = arcpy.mapping.Layer(Name)
    desc = arcpy.Describe(inWorkSpace)
    typ = str(desc.workspaceType)
    if typ == "FileSystem":
        typ = "RASTER_WORKSPACE"
    else:
        if typ == "LocalDatabase":
            if desc.workspaceFactoryProgID == "esriDataSourcesGDB.FileGDBWorkspaceFactory.1":
                typ = "FILEGDB_WORKSPACE"
            else:
                typ = "ACCESS_WORKSPACE"

    lyr_file.replaceDataSource(inWorkSpace, typ, Name)
    lyr_file.name = Name
    mxd = arcpy.mapping.MapDocument("CURRENT")
    df = arcpy.mapping.ListDataFrames(mxd)[0]
    arcpy.mapping.AddLayer(df, lyr_file,"TOP")
    del lyr_file
    del mxd
    del df
    del desc
    arcpy.RefreshActiveView()
    arcpy.RefreshTOC()

Attachments

Outcomes