Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

arcpy.MakeRasterLayer_management() failed in toolbox script

$
0
0
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.
Code:

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:
Code:

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:
Code:

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:
Attachment 30058
Attachment 30059
Attached Thumbnails
Click image for larger version

Name:	Capture.JPG‎
Views:	N/A
Size:	34.9 KB
ID:	30058   Click image for larger version

Name:	Capture1.JPG‎
Views:	N/A
Size:	26.7 KB
ID:	30059  

Viewing all articles
Browse latest Browse all 2485

Trending Articles