<?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 Layer from Pywin to open mxd using Python in ArcGIS Network Analyst Questions</title>
    <link>https://community.esri.com/t5/arcgis-network-analyst-questions/adding-layer-from-pywin-to-open-mxd-using-python/m-p/517210#M5064</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;on a lark, could you place the file in a folder rather than in the root directory&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 19 Oct 2015 14:20:45 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2015-10-19T14:20:45Z</dc:date>
    <item>
      <title>Adding Layer from Pywin to open mxd using Python</title>
      <link>https://community.esri.com/t5/arcgis-network-analyst-questions/adding-layer-from-pywin-to-open-mxd-using-python/m-p/517207#M5061</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Trying to automate some editing tasks and then exporting the files to pdf's. I'm getting stuck with loading the layers into ArcMap. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can do it in the Python window using the standard: &lt;/P&gt;&lt;P&gt;arcpy.mapping.MapDocument("CURRENT")&lt;/P&gt;&lt;P&gt;df = arcpy.mapping.ListDataFrames(mxd,"*")[0]&lt;/P&gt;&lt;P&gt;newlayer = arcpy.mapping.Layer(r"H:\2.shp")&lt;/P&gt;&lt;P&gt;arcpy.mapping.AddLayer(df, newlayer,"TOP")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but when I try to do it by referencing the mxd path instead of "CURRENT" in Pywin or a script tool (see below), it runs through but doesn't actually load the shapefile onto the map:&lt;/P&gt;&lt;P&gt;arcpy.mapping.MapDocument(&lt;STRONG&gt;r&lt;/STRONG&gt;"&lt;STRONG&gt;H:\map2.mxd&lt;/STRONG&gt;")&lt;/P&gt;&lt;P&gt;df = arcpy.mapping.ListDataFrames(mxd,"*")[0]&lt;/P&gt;&lt;P&gt;newlayer = arcpy.mapping.Layer(r"H:\2.shp")&lt;/P&gt;&lt;P&gt;arcpy.mapping.AddLayer(df, newlayer,"TOP")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried the second code in the Arc Python window, and it doesn't work there either. Any ideas? I'm sure it's a simple issue...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Oct 2015 20:21:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-network-analyst-questions/adding-layer-from-pywin-to-open-mxd-using-python/m-p/517207#M5061</guid>
      <dc:creator>TobyJacobs1</dc:creator>
      <dc:date>2015-10-15T20:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Layer from Pywin to open mxd using Python</title>
      <link>https://community.esri.com/t5/arcgis-network-analyst-questions/adding-layer-from-pywin-to-open-mxd-using-python/m-p/517208#M5062</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you try running the following and let me know if this works for you?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
mxd = arcpy.mapping.MapDocument(r"H:\map2.mxd")
df&amp;nbsp; = arcpy.mapping.ListDataFrames(mxd)[0]
lyr = arcpy.management.MakeFeatureLayer(r"H:\2.shp").getOutput(0)
arcpy.mapping.AddLayer(df, lyr, "TOP")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would say you'd want to note two things here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;You should avoid using arcpy.Layer against the shapefile directly. This method is intended to be used against layer files (i.e. files that end in .lyr) as noted in the documentation.&lt;BR /&gt;&lt;BR /&gt;&lt;IMG __jive_id="131392" alt="layer.png" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/131392_layer.png" style="width: 620px; height: 170px;" /&gt;&lt;/LI&gt;&lt;LI&gt;You will only see the layers added to an open map document if you run the code within ArcMap and utilize the &lt;STRONG&gt;CURRENT &lt;/STRONG&gt;keyword. Otherwise you will need to run the code, save the map via the code, and then open the map document on the system to see the changes.&lt;/LI&gt;&lt;/OL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:33:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-network-analyst-questions/adding-layer-from-pywin-to-open-mxd-using-python/m-p/517208#M5062</guid>
      <dc:creator>FreddieGibson</dc:creator>
      <dc:date>2021-12-11T22:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Layer from Pywin to open mxd using Python</title>
      <link>https://community.esri.com/t5/arcgis-network-analyst-questions/adding-layer-from-pywin-to-open-mxd-using-python/m-p/517209#M5063</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the feedback, but that doesn't seem to solve the issue. It looks&lt;/P&gt;&lt;P&gt;like others had this issue in 10.0, but I'm using 10.3. Seems like a major&lt;/P&gt;&lt;P&gt;bug...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Oct 2015 13:01:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-network-analyst-questions/adding-layer-from-pywin-to-open-mxd-using-python/m-p/517209#M5063</guid>
      <dc:creator>TobyJacobs1</dc:creator>
      <dc:date>2015-10-19T13:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Layer from Pywin to open mxd using Python</title>
      <link>https://community.esri.com/t5/arcgis-network-analyst-questions/adding-layer-from-pywin-to-open-mxd-using-python/m-p/517210#M5064</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;on a lark, could you place the file in a folder rather than in the root directory&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Oct 2015 14:20:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-network-analyst-questions/adding-layer-from-pywin-to-open-mxd-using-python/m-p/517210#M5064</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-10-19T14:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Layer from Pywin to open mxd using Python</title>
      <link>https://community.esri.com/t5/arcgis-network-analyst-questions/adding-layer-from-pywin-to-open-mxd-using-python/m-p/517211#M5065</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, I tried moving it all over the place with no change in result&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Oct 2015 14:44:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-network-analyst-questions/adding-layer-from-pywin-to-open-mxd-using-python/m-p/517211#M5065</guid>
      <dc:creator>TobyJacobs1</dc:creator>
      <dc:date>2015-10-19T14:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Layer from Pywin to open mxd using Python</title>
      <link>https://community.esri.com/t5/arcgis-network-analyst-questions/adding-layer-from-pywin-to-open-mxd-using-python/m-p/517212#M5066</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can't find arcpy.mapping.MakeFeature layer ... there is a Layer property&amp;nbsp; in the &lt;A href="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-mapping/alphabeticallistofclasses.htm"&gt;arcpy.mapping classes​ &lt;/A&gt;​and no reference in the &lt;A href="http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-mapping/alphabeticallistoffunctions.htm"&gt;arcpy.mapping functions&lt;/A&gt;​ can you provide a link or are you referring to the datamanagement tool of the same name?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Oct 2015 15:03:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-network-analyst-questions/adding-layer-from-pywin-to-open-mxd-using-python/m-p/517212#M5066</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-10-19T15:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Layer from Pywin to open mxd using Python</title>
      <link>https://community.esri.com/t5/arcgis-network-analyst-questions/adding-layer-from-pywin-to-open-mxd-using-python/m-p/517213#M5067</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm assuming it was the data management tool&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Oct 2015 15:05:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-network-analyst-questions/adding-layer-from-pywin-to-open-mxd-using-python/m-p/517213#M5067</guid>
      <dc:creator>TobyJacobs1</dc:creator>
      <dc:date>2015-10-19T15:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Layer from Pywin to open mxd using Python</title>
      <link>https://community.esri.com/t5/arcgis-network-analyst-questions/adding-layer-from-pywin-to-open-mxd-using-python/m-p/517214#M5068</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was just curious whether Freddie's code worked... and order for it to persist, the layer would have to be made permanent since it won't be saved otherwise&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fdesktop.arcgis.com%2Fen%2Fdesktop%2Flatest%2Ftools%2Fdata-management-toolbox%2Fmake-feature-layer.htm" rel="nofollow" target="_blank"&gt;http://desktop.arcgis.com/en/desktop/latest/tools/data-management-toolbox/make-feature-layer.htm&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Oct 2015 15:12:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-network-analyst-questions/adding-layer-from-pywin-to-open-mxd-using-python/m-p/517214#M5068</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-10-19T15:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Layer from Pywin to open mxd using Python</title>
      <link>https://community.esri.com/t5/arcgis-network-analyst-questions/adding-layer-from-pywin-to-open-mxd-using-python/m-p/517215#M5069</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry about that Dan. That was a typo on my part. It should say arcpy.management.MakeFeatureLayer&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Oct 2015 16:50:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-network-analyst-questions/adding-layer-from-pywin-to-open-mxd-using-python/m-p/517215#M5069</guid>
      <dc:creator>FreddieGibson</dc:creator>
      <dc:date>2015-10-19T16:50:57Z</dc:date>
    </item>
  </channel>
</rss>

