I have shortened the code to omit the slicing part, and I actually get layer files in my folder. BUT they are composites - all 17 bands. I had understood that by including a band index in the MakeRasterLayer operation, I would get only that band.Have I misunderstood or just done something wrong?Thanks for any insight.krs #import system modules
import arcpy, os, sys, traceback
from arcpy import env
#set workspace
env.workspace="L:\FINAL\\output"
#print ("workspace defined")
#import mapping module and define the map
import arcpy.mapping
mxd=arcpy.mapping.MapDocument("L:\FINAL\\projectMap.mxd")
#print ("map defined")
#define data frame
df=arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
#print("data frame found")
#import spatial analyst
from arcpy.sa import *
print ("SA imported")
def main():
try:
if arcpy.CheckExtension("spatial") == "Available":
#checkout extension
arcpy.CheckOutExtension("spatial")
print("SA available and checked out")
#overwrite files with the same name
env.overwriteOutput = True
#make list of rasters
tiles=arcpy.ListDatasets("CP*", "Raster")
print("classes listed")
#make list of bands in each raster
bands=["BLANK","cld_w_1","cld_dk2", "evgn_3", \
"gr_grs_4", "decid_5", "drm_grs_6", "soil_7", \
"ipv_dk_8", "ipv_md_9", "ipv_gn_10", "ipv_lt_11",\
"conc_12", "ipv_br_13", "shv_ip_14", \
"shb_ip_15", "shv_vg_16", "shb_vg_17"]
#Loop through folder making raster layer by band
for tile in tiles:
for band in bands[1:18]:
arcpy.MakeRasterLayer_management (tile, band, "", "", "bands[]")
arcpy.SaveToLayerFile_management(band, band + "lyr", "RELATIVE")
except:
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
pymsg = "PYTHON ERRORS:\nTraceback Info:\n" + tbinfo + "\nError Info:\n " + str(sys.exc_type) + ": " + str(sys.exc_value) + "\n"
msgs = "ARCPY ERRORS:\n" + arcpy.GetMessages(2) + "\n"
arcpy.AddError(msgs)
arcpy.AddError(pymsg)
print msgs
print pymsg
arcpy.AddMessage(arcpy.GetMessages(1))
print arcpy.GetMessages(1)
main()