<?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 Add layer script not working in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/add-layer-script-not-working/m-p/94844#M7386</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;I am attempting to use an add layer script to add a layer which points to an ArcGIS Server Map Service to the current map document.&amp;nbsp; If you could tell me why this script is not working I would appreciate it:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = r"Z:\Imagery"
&amp;nbsp;&amp;nbsp;&amp;nbsp; print workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT")
&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd,'Layers')[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; addLayer = arcpy.mapping.Layer(r"Z:\Imagery\2011VBMP.lyr")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshTOC()
&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd, addLayer
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Error"&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Justin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 28 Feb 2012 12:47:21 GMT</pubDate>
    <dc:creator>JustinRay1</dc:creator>
    <dc:date>2012-02-28T12:47:21Z</dc:date>
    <item>
      <title>Add layer script not working</title>
      <link>https://community.esri.com/t5/python-questions/add-layer-script-not-working/m-p/94844#M7386</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;I am attempting to use an add layer script to add a layer which points to an ArcGIS Server Map Service to the current map document.&amp;nbsp; If you could tell me why this script is not working I would appreciate it:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = r"Z:\Imagery"
&amp;nbsp;&amp;nbsp;&amp;nbsp; print workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT")
&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd,'Layers')[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; addLayer = arcpy.mapping.Layer(r"Z:\Imagery\2011VBMP.lyr")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshTOC()
&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd, addLayer
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Error"&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Justin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2012 12:47:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-layer-script-not-working/m-p/94844#M7386</guid>
      <dc:creator>JustinRay1</dc:creator>
      <dc:date>2012-02-28T12:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: Add layer script not working</title>
      <link>https://community.esri.com/t5/python-questions/add-layer-script-not-working/m-p/94845#M7387</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can start by removing the print workspace line unless you have that variable set somewhere else.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2012 12:56:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-layer-script-not-working/m-p/94845#M7387</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2012-02-28T12:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Add layer script not working</title>
      <link>https://community.esri.com/t5/python-questions/add-layer-script-not-working/m-p/94846#M7388</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ah, thank you.&amp;nbsp; Not sure what I was thinking there.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Feb 2012 13:15:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/add-layer-script-not-working/m-p/94846#M7388</guid>
      <dc:creator>JustinRay1</dc:creator>
      <dc:date>2012-02-29T13:15:40Z</dc:date>
    </item>
  </channel>
</rss>

