Hello,Recently I have been trying to implement the "Make Raster Layer" tool in a python script. The code I have is as follow, which takes a file path as the major input with a boolean to indicate whether debugging messages should be output to a file.import arcpy debugmsg = "" # Receive the parameters from the toolbox dialog # - the path of the input image in_img_path = arcpy.GetParameterAsText(0) debugmsg += "input: " + in_img_path + "\n" # - the choice of outputting a debug text file debug = arcpy.GetParameter(1) # set up variables tmp = in_img_path.split("\\") layername = tmp[len(tmp)-1].split(".")[0] debugmsg += "layer name: " + layername + "\n" try: # -- generate a raster layer from image arcpy.MakeRasterLayer_management(imgname, layername, "#") debugmsg += arcpy.GetMessages()+"\n" except: debugmsg += "Make Raster Layer failed.\n" debugmsg += arcpy.GetMessages()+"\n" print debugmsg if debug: f = open(in_img_path[0:len(in_img_path)-4]+'_debug.txt', 'w') f.write(debugmsg) f.close()
However, when I executed it, the Make Raster Layer function failed as indicated in the debugging output:input: I:\WIN\Desktop\image\big.png layer name: big Make Raster Layer failed.
I used the same input directly in the Python window of ArcGIS and it succeeded with a layer named "big" shown up in the table of content. The command follows:arcpy.MakeRasterLayer_management(r"I:\WIN\Desktop\image\big.png","big")
So, I am confused about why the same command executed differently. Does anyone have the same experience and hopefully a solution? Any suggestion is appreciated.Some screenshots of invoking the script and the execution result for your reference:[ATTACH=CONFIG]30058[/ATTACH][ATTACH=CONFIG]30059[/ATTACH]