<?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: adding raster data from a file gdb to the current mxd  TOC using python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/adding-raster-data-from-a-file-gdb-to-the-current/m-p/601610#M47010</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.MakeRasterLayer_management is meant to other purpose, so you can skip this. Code below should help. If you want to change layer name use:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;addLayer.name = &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;new_name&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;before adding layer to map doc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
fc_list=[fc_meanSun,fc_lowSun]
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
for ras_name in fc_list:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc=fc_path+'\\'+ras_name
&amp;nbsp;&amp;nbsp;&amp;nbsp; addLayer = arcpy.mapping.Layer(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df,addLayer)

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Arek&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 01:47:50 GMT</pubDate>
    <dc:creator>ArkadiuszMatoszka</dc:creator>
    <dc:date>2021-12-12T01:47:50Z</dc:date>
    <item>
      <title>adding raster data from a file gdb to the current mxd  TOC using python</title>
      <link>https://community.esri.com/t5/python-questions/adding-raster-data-from-a-file-gdb-to-the-current/m-p/601609#M47009</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want to create a toolbox using python that adds two sets of raster data located in a gdb into my current .mxd&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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:&amp;nbsp; It is also not the original name for the raster but the name with an added number.&amp;nbsp; I want to add the original raster and its original name.&amp;nbsp; I used 'n' in the for loop so that I could add an index to the name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fc_list=[fc_meanSun,fc_lowSun]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for n in range(len(fc_list)):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fc_add=fc_list&lt;N&gt;&lt;/N&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fc=fc_path+'\\'+fc_add&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xxx=fc_add+str(n)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeRasterLayer_management(fc, xxx)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; addLayer = arcpy.mapping.Layer(xxx)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df,addLayer)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Oct 2012 17:17:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-raster-data-from-a-file-gdb-to-the-current/m-p/601609#M47009</guid>
      <dc:creator>DaleSchaper</dc:creator>
      <dc:date>2012-10-17T17:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: adding raster data from a file gdb to the current mxd  TOC using python</title>
      <link>https://community.esri.com/t5/python-questions/adding-raster-data-from-a-file-gdb-to-the-current/m-p/601610#M47010</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.MakeRasterLayer_management is meant to other purpose, so you can skip this. Code below should help. If you want to change layer name use:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;addLayer.name = &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;new_name&lt;/SPAN&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;before adding layer to map doc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
fc_list=[fc_meanSun,fc_lowSun]
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
for ras_name in fc_list:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc=fc_path+'\\'+ras_name
&amp;nbsp;&amp;nbsp;&amp;nbsp; addLayer = arcpy.mapping.Layer(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df,addLayer)

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Arek&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:47:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-raster-data-from-a-file-gdb-to-the-current/m-p/601610#M47010</guid>
      <dc:creator>ArkadiuszMatoszka</dc:creator>
      <dc:date>2021-12-12T01:47:50Z</dc:date>
    </item>
    <item>
      <title>Re: adding raster data from a file gdb to the current mxd  TOC using python</title>
      <link>https://community.esri.com/t5/python-questions/adding-raster-data-from-a-file-gdb-to-the-current/m-p/601611#M47011</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You could create a script that runs the 'Make Raster Layer' function for each raster.&amp;nbsp; If you have 'Add results of geoprocessing to the display" checked on within the Geoprocessing options, the raster layers will automatically be added to the current map document.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.MakeRasterLayer_management("C:/DATA/RASTER/DEM/example", "example")
arcpy.MakeRasterLayer_management("C:/DATA/RASTER/DEM/example2", "example2")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:47:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-raster-data-from-a-file-gdb-to-the-current/m-p/601611#M47011</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-12T01:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: adding raster data from a file gdb to the current mxd  TOC using python</title>
      <link>https://community.esri.com/t5/python-questions/adding-raster-data-from-a-file-gdb-to-the-current/m-p/601612#M47012</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Arek,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks for the quick reply.&amp;nbsp; This should be a simple task!&amp;nbsp; I changed the script to your approach but received an error message:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; Object: CreateObject Layer invalid data source&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think it has something to do with rasters being treated differently than feature classes or shape files.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;not sure how to fix this&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;dale&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi,&lt;BR /&gt;arcpy.MakeRasterLayer_management is meant to other purpose, so you can skip this. Code below should help. If you want to change layer name use:&lt;BR /&gt;addLayer.name = &lt;SPAN style="font-style:italic;"&gt;new_name&lt;/SPAN&gt; &lt;BR /&gt;before adding layer to map doc.&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
fc_list=[fc_meanSun,fc_lowSun]
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
for ras_name in fc_list:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc=fc_path+'\\'+ras_name
&amp;nbsp;&amp;nbsp;&amp;nbsp; addLayer = arcpy.mapping.Layer(fc)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df,addLayer)

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Regards.&lt;BR /&gt;Arek&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:47:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-raster-data-from-a-file-gdb-to-the-current/m-p/601612#M47012</guid>
      <dc:creator>DaleSchaper</dc:creator>
      <dc:date>2021-12-12T01:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: adding raster data from a file gdb to the current mxd  TOC using python</title>
      <link>https://community.esri.com/t5/python-questions/adding-raster-data-from-a-file-gdb-to-the-current/m-p/601613#M47013</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jake,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I have the geoprocessing option checked.&amp;nbsp; I think it does it by default.&amp;nbsp; The new rasters appear and then disappear.&amp;nbsp; But, I also had to rename them and create the new layers.&amp;nbsp; If I did them manually in the .mxd then they would be added from the .gdb.&amp;nbsp; Am I suppose to do a save or close a schema lock?&amp;nbsp; This seems as if it should be a simple and common task so I must be missing a basic point to it all.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks for your quick reply&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;dale&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You could create a script that runs the 'Make Raster Layer' function for each raster.&amp;nbsp; If you have 'Add results of geoprocessing to the display" checked on within the Geoprocessing options, the raster layers will automatically be added to the current map document.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.MakeRasterLayer_management("C:/DATA/RASTER/DEM/example", "example")
arcpy.MakeRasterLayer_management("C:/DATA/RASTER/DEM/example2", "example2")&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:47:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-raster-data-from-a-file-gdb-to-the-current/m-p/601613#M47013</guid>
      <dc:creator>DaleSchaper</dc:creator>
      <dc:date>2021-12-12T01:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: adding raster data from a file gdb to the current mxd  TOC using python</title>
      <link>https://community.esri.com/t5/python-questions/adding-raster-data-from-a-file-gdb-to-the-current/m-p/601614#M47014</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jake,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I just ran this simple script where there is a polygon feature class in the .gdb and want to add it to the TOC of the current .mxd using a tool script.&amp;nbsp; It tells me that I have an invalid data path.&amp;nbsp; That is the data path ... so what am I missing&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dale&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; addLayer = arcpy.mapping.Layer(r"F:\GIS 249\Wk02_Spatial Analyst\Thursday\Learn01\VirtualCampus\LearnSA9\MapAlgebra\Piru.gdb\FirePer")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df,addLayer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;results error message:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Start Time: Thu Oct 18 11:05:49 2012&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Running script AddFireZonePoly...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;type 'exceptions.ValueError'&amp;gt;: Object: CreateObject Layer invalid data source&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (AddFireZonePoly).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed at Thu Oct 18 11:05:51 2012 (Elapsed Time: 2.00 seconds)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Oct 2012 17:21:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-raster-data-from-a-file-gdb-to-the-current/m-p/601614#M47014</guid>
      <dc:creator>DaleSchaper</dc:creator>
      <dc:date>2012-10-18T17:21:02Z</dc:date>
    </item>
    <item>
      <title>Re: adding raster data from a file gdb to the current mxd  TOC using python</title>
      <link>https://community.esri.com/t5/python-questions/adding-raster-data-from-a-file-gdb-to-the-current/m-p/601615#M47015</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Dale,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Your code appears correct.&amp;nbsp; What version of ArcGIS are you running?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, try specifying the UNC path rather than the network drive.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
addLayer = arcpy.mapping.Layer(r"&lt;STRONG&gt;\\&amp;lt;server name&amp;gt;&lt;/STRONG&gt;\GIS 249\Wk02_Spatial&amp;nbsp; Analyst\Thursday\Learn01\VirtualCampus\LearnSA9\MapAlgebra\Piru.gdb\FirePer")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:48:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-raster-data-from-a-file-gdb-to-the-current/m-p/601615#M47015</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-12T01:48:00Z</dc:date>
    </item>
  </channel>
</rss>

