<?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: Add Layer Error in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/add-layer-error/m-p/352457#M27621</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You have to create a layer object from the pathname and then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;specify the DataFrame that you are adding the layer object into.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "New Data Frame")[0]
addLayer = arcpy.mapping.Layer(r"C:\Project\Data\Orthophoto.lyr")
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 16:32:55 GMT</pubDate>
    <dc:creator>KimOllivier</dc:creator>
    <dc:date>2021-12-11T16:32:55Z</dc:date>
    <item>
      <title>Add Layer Error</title>
      <link>https://community.esri.com/t5/python-questions/add-layer-error/m-p/352456#M27620</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am setting up a file to format a map template.&amp;nbsp; I am stuck at the Add Layer section.&amp;nbsp; I have a dictionary which is layer name:layer path.&amp;nbsp; I want to grab all the layer paths and add them as layers to the map template.&amp;nbsp; How can I fix my code?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;TemplateLayers=(r"\\...\TemplateLayers.txt")
lyrDict={}
with open (TemplateLayers) as f:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for line in f:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (key,val)=line.split(",")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrDict[(key)]=val
f.close()

print lyrDict

#Step 2: Pull the layers into the MXD at the bottom of the data frame from the dictionary.
for val in lyrDict.values():
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer("",(val),"Bottom") &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;SPAN&gt;I get: Runtime error &amp;lt;type 'exceptions.AssertionError'&amp;gt;:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When I print my dictionary it looks like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{'Roads':'\\\\filepath\\filename.lyr',etc....}&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Nov 2012 18:32:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-layer-error/m-p/352456#M27620</guid>
      <dc:creator>MaryM</dc:creator>
      <dc:date>2012-11-09T18:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: Add Layer Error</title>
      <link>https://community.esri.com/t5/python-questions/add-layer-error/m-p/352457#M27621</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You have to create a layer object from the pathname and then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;specify the DataFrame that you are adding the layer object into.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "New Data Frame")[0]
addLayer = arcpy.mapping.Layer(r"C:\Project\Data\Orthophoto.lyr")
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:32:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-layer-error/m-p/352457#M27621</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2021-12-11T16:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: Add Layer Error</title>
      <link>https://community.esri.com/t5/python-questions/add-layer-error/m-p/352458#M27622</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have the path to the layer, I can cat the object arcpy.mapping... in front of all of them for each.&amp;nbsp; Does addLayer have to be referenced to a single variable or can it be referenced to a path name?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Nov 2012 11:05:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-layer-error/m-p/352458#M27622</guid>
      <dc:creator>MaryM</dc:creator>
      <dc:date>2012-11-13T11:05:59Z</dc:date>
    </item>
    <item>
      <title>Re: Add Layer Error</title>
      <link>https://community.esri.com/t5/python-questions/add-layer-error/m-p/352459#M27623</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;AddLayer takes 3 arguments:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
AddLayer (data_frame, add_layer, {add_position})
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;where data_frame must be instance of arcpy.mapping.DataFrame, add_layer must be instance of arcpy.Layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;All you have to do is define data frame of mxd and create arcpy.Layer()'s from paths so:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
TemplateLayers=(r"\\...\TemplateLayers.txt")
lyrDict={}
with open (TemplateLayers) as f:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for line in f:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; key,val=line.split(",")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrDict[key]=val
f.close()

print lyrDict
mxd = arcpy.mapping.MapDocument('path\\to\\mxd.mxd')
df = arcpy.mapping.ListDataFrames(mxd)[0]
#Step 2: Pull the layers into the MXD at the bottom of the data frame from the dictionary.
for val in lyrDict.values():
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df,arcpy.Layer(val),"Bottom")
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;That should do.&lt;/SPAN&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>Sat, 11 Dec 2021 16:32:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-layer-error/m-p/352459#M27623</guid>
      <dc:creator>ArkadiuszMatoszka</dc:creator>
      <dc:date>2021-12-11T16:32:57Z</dc:date>
    </item>
  </channel>
</rss>

