schaperd

adding raster data from a file gdb to the current mxd  TOC using python

Discussion created by schaperd on Oct 17, 2012
Latest reply on Oct 18, 2012 by jskinner-esristaff
I want to create a toolbox using python that adds two sets of raster data located in a gdb into my current .mxd

The best that I can do is create some new layer and then have it adds into the TOC but then it disappears when the tool completes:  It is also not the original name for the raster but the name with an added number.  I want to add the original raster and its original name.  I used 'n' in the for loop so that I could add an index to the name.


    fc_list=[fc_meanSun,fc_lowSun]


    mxd = arcpy.mapping.MapDocument("CURRENT")
    df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
    for n in range(len(fc_list)):
        fc_add=fc_list[n]
        fc=fc_path+'\\'+fc_add
        xxx=fc_add+str(n)

        arcpy.MakeRasterLayer_management(fc, xxx)
        addLayer = arcpy.mapping.Layer(xxx)
        arcpy.mapping.AddLayer(df,addLayer)

Outcomes