<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: arcpy.MakeRasterLayer_management() failed in toolbox script in Transportation Questions</title>
    <link>https://community.esri.com/t5/transportation-questions/arcpy-makerasterlayer-management-failed-in-toolbox/m-p/646008#M2131</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: zhengdx04&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;In your MakeRasterLayer function, it doesn't look like you have the 'imgname' variable defined to anything.&amp;nbsp; Try the following instead:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.MakeRasterLayer_management(in_img_path, layername, "#")&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for catching that Jake! After correction, the code executed MakeRasterLayer_management() function successfully. However, I still couldn't see it add any layer into my map. When I used it in Python window, it did. Any additional thought?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 23 Dec 2013 19:16:23 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2013-12-23T19:16:23Z</dc:date>
    <item>
      <title>arcpy.MakeRasterLayer_management() failed in toolbox script</title>
      <link>https://community.esri.com/t5/transportation-questions/arcpy-makerasterlayer-management-failed-in-toolbox/m-p/646006#M2129</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy&amp;nbsp; 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"&amp;nbsp; # - the choice of outputting a debug text file debug = arcpy.GetParameter(1)&amp;nbsp; # set up variables tmp = in_img_path.split("\\") layername = tmp[len(tmp)-1].split(".")[0] debugmsg += "layer name: " + layername + "\n"&amp;nbsp; try: &amp;nbsp;&amp;nbsp;&amp;nbsp; # -- generate a raster layer from image &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeRasterLayer_management(imgname, layername, "#") &amp;nbsp;&amp;nbsp;&amp;nbsp; debugmsg += arcpy.GetMessages()+"\n" except: &amp;nbsp;&amp;nbsp;&amp;nbsp; debugmsg += "Make Raster Layer failed.\n" &amp;nbsp;&amp;nbsp;&amp;nbsp; debugmsg += arcpy.GetMessages()+"\n"&amp;nbsp; print debugmsg if debug: &amp;nbsp;&amp;nbsp;&amp;nbsp; f = open(in_img_path[0:len(in_img_path)-4]+'_debug.txt', 'w') &amp;nbsp;&amp;nbsp;&amp;nbsp; f.write(debugmsg) &amp;nbsp;&amp;nbsp;&amp;nbsp; f.close()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, when I executed it, the Make Raster Layer function failed as indicated in the debugging output:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;input: I:\WIN\Desktop\image\big.png layer name: big Make Raster Layer failed.&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.MakeRasterLayer_management(r"I:\WIN\Desktop\image\big.png","big")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Some screenshots of invoking the script and the execution result for your reference:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]30058[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]30059[/ATTACH]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 21 Dec 2013 02:30:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/arcpy-makerasterlayer-management-failed-in-toolbox/m-p/646006#M2129</guid>
      <dc:creator>DongxiZheng</dc:creator>
      <dc:date>2013-12-21T02:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.MakeRasterLayer_management() failed in toolbox script</title>
      <link>https://community.esri.com/t5/transportation-questions/arcpy-makerasterlayer-management-failed-in-toolbox/m-p/646007#M2130</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In your MakeRasterLayer function, it doesn't look like you have the 'imgname' variable defined to anything.&amp;nbsp; Try the following instead:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.MakeRasterLayer_management(in_img_path, layername, "#")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Dec 2013 10:23:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/arcpy-makerasterlayer-management-failed-in-toolbox/m-p/646007#M2130</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2013-12-23T10:23:13Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.MakeRasterLayer_management() failed in toolbox script</title>
      <link>https://community.esri.com/t5/transportation-questions/arcpy-makerasterlayer-management-failed-in-toolbox/m-p/646008#M2131</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: zhengdx04&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;In your MakeRasterLayer function, it doesn't look like you have the 'imgname' variable defined to anything.&amp;nbsp; Try the following instead:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.MakeRasterLayer_management(in_img_path, layername, "#")&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for catching that Jake! After correction, the code executed MakeRasterLayer_management() function successfully. However, I still couldn't see it add any layer into my map. When I used it in Python window, it did. Any additional thought?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Dec 2013 19:16:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/arcpy-makerasterlayer-management-failed-in-toolbox/m-p/646008#M2131</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2013-12-23T19:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.MakeRasterLayer_management() failed in toolbox script</title>
      <link>https://community.esri.com/t5/transportation-questions/arcpy-makerasterlayer-management-failed-in-toolbox/m-p/646009#M2132</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Add the following to the end of your code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;mxd = arcpy.mapping.MapDocument("CURRENT") df&amp;nbsp; = arcpy.mapping.ListDataFrames(mxd)[0]&amp;nbsp; lyr = arcpy.mapping.Layer(layername)&amp;nbsp; arcpy.mapping.AddLayer(df, lyr) arcpy.RefreshTOC() arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Dec 2013 14:31:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/arcpy-makerasterlayer-management-failed-in-toolbox/m-p/646009#M2132</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2013-12-27T14:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.MakeRasterLayer_management() failed in toolbox script</title>
      <link>https://community.esri.com/t5/transportation-questions/arcpy-makerasterlayer-management-failed-in-toolbox/m-p/646010#M2133</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Original User: zhengdx04&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Add the following to the end of your code:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;mxd = arcpy.mapping.MapDocument("CURRENT")
df&amp;nbsp; = arcpy.mapping.ListDataFrames(mxd)[0]

lyr = arcpy.mapping.Layer(layername)

arcpy.mapping.AddLayer(df, lyr)
arcpy.RefreshTOC()
arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;A lot thanks! It is the exact solution, although the last two lines of refreshing code are not a must.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:25:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/transportation-questions/arcpy-makerasterlayer-management-failed-in-toolbox/m-p/646010#M2133</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T03:25:23Z</dc:date>
    </item>
  </channel>
</rss>

