<?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: addLayer error in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/579878#M45474</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you're working within ArcMap, the MakeFeatureLayer and MakeRasterLayer tools should do what you want.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 04 Mar 2011 21:01:42 GMT</pubDate>
    <dc:creator>JasonScheirer</dc:creator>
    <dc:date>2011-03-04T21:01:42Z</dc:date>
    <item>
      <title>addLayer error</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/579875#M45471</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Folks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to load some image layers to a dataframe. The file name / path of the image is read from a feature class using a search cursor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
...

ss = arcpy.SearchCursor("MyLayer", "", "", "FILENAME")
for s in ss:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(s.FILENAME)
&amp;nbsp;&amp;nbsp;&amp;nbsp; addLayer = arcpy.mapping.Layer(s.FILENAME)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, addLayer, "TOP")
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The AddMessage works and shows the correct name, but I get the following error on the addLayer code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&amp;lt;type 'exceptions.ValueError'&amp;gt;: Object: CreateObject Layer invalid data source&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is it possible that it's a path error? The value from the feature class is a Windows path so it contains \'s. I've post-processed the name to replace \'s with /'s, but that didn't make a difference.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I assume addLayer works with .sid, .tif, etc?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Scott&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:55:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/579875#M45471</guid>
      <dc:creator>ScottOatley</dc:creator>
      <dc:date>2021-12-12T00:55:53Z</dc:date>
    </item>
    <item>
      <title>Re: addLayer error</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/579876#M45472</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can only create layer objects from .lyr files.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Mar 2011 16:18:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/579876#M45472</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2011-03-04T16:18:37Z</dc:date>
    </item>
    <item>
      <title>Re: addLayer error</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/579877#M45473</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;You can only create layer objects from .lyr files.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;OK. So is there some other command that can be used to directly add data to the TOC? Or some other method that doesn't involve creating a lyr file? Our production work involves loading and removing layers repeatedly. I don't really want to create temporary files all the time just to load data.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Scott&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Mar 2011 17:19:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/579877#M45473</guid>
      <dc:creator>ScottOatley</dc:creator>
      <dc:date>2011-03-04T17:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: addLayer error</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/579878#M45474</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you're working within ArcMap, the MakeFeatureLayer and MakeRasterLayer tools should do what you want.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Mar 2011 21:01:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/579878#M45474</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2011-03-04T21:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: addLayer error</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/579879#M45475</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Greetings:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Well, I've been trying to get this to work. I got my code to run without error. However, nothing shows up in the TOC. I added an arcpy.RefreshTOC() statement, but that didn't change the result. I decided to make a model and dump the code to python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# ---------------------------------------------------------------------------
# makeRaster.py
# Created on: 2011-03-07 15:34:04.00000
#&amp;nbsp;&amp;nbsp; (generated by ArcGIS/ModelBuilder)
# Description: 
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy

# Local variables:
layer_jpg = "C:\\tmp\\layer.jpg"
MakeRas_jpg2 = "MakeRas_jpg2"

# Process: Make Raster Layer
arcpy.MakeRasterLayer_management(layer_jpg, MakeRas_jpg2, "", "-0.5 -13868.5 13765.5 0.5", "")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The model worked and added the "MakeRas_jpg2" layer to the TOC. Running it as a python script, it runs to completion successfully, but doesn't add the new layer to the TOC. Same result if I add the "Refresh" command.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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;Scott&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:55:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/579879#M45475</guid>
      <dc:creator>ScottOatley</dc:creator>
      <dc:date>2021-12-12T00:55:56Z</dc:date>
    </item>
    <item>
      <title>Re: addLayer error</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/579880#M45476</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You have to run it as a tool and add an output parameter. In the tool the parameter is set to DERIVED and in the script you set the parameter to the layer.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Mar 2011 22:41:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/579880#M45476</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2011-03-07T22:41:50Z</dc:date>
    </item>
    <item>
      <title>Re: addLayer error</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/579881#M45477</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;BLOCKQUOTE class="jive-quote"&gt;You have to run it as a tool and add an output parameter. In the tool the parameter is set to DERIVED and in the script you set the parameter to the layer.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;OK, I got this to work per the above. My next issue I've been working on is using the DERIVED output parameter as MULTIVALUE. I tried the following. I do a select by location in a table and then do a search cursor on a field containing full file names. I've got 1 input parameter so I set my index at 1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.SelectLayerByLocation_management( blah, blah, ... )
ss = arcpy.SearchCursor( ... )
for s in ss:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetParameterAsText(1, arcpy.MakeRasterLayer_management(s.FILENAME, os.path.basename(s.FILENAME)))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This sort of works as it loads the image layer for the last record in the search cursor. Other than setting multivalue to yes on the tool properties, what else must be done?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Scott&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:55:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/579881#M45477</guid>
      <dc:creator>ScottOatley</dc:creator>
      <dc:date>2021-12-12T00:55:58Z</dc:date>
    </item>
    <item>
      <title>Re: addLayer error</title>
      <link>https://community.esri.com/t5/python-questions/addlayer-error/m-p/579882#M45478</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Scott, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Did you ever get this to return multiple values?&amp;nbsp; I am working on something similar.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Nathan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Aug 2011 17:45:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/addlayer-error/m-p/579882#M45478</guid>
      <dc:creator>NathanPugh</dc:creator>
      <dc:date>2011-08-05T17:45:29Z</dc:date>
    </item>
  </channel>
</rss>

