<?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: How do I add feature layers to map through python? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-do-i-add-feature-layers-to-map-through-python/m-p/29817#M2327</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Dan!!! I got it working. Here is the full syntax and parameters:&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;import arcpy, os&lt;BR /&gt;arcpy.CheckOutExtension("network")&lt;/P&gt;&lt;P&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;path = arcpy.GetParameterAsText(0)&lt;BR /&gt;gdb = arcpy.GetParameterAsText(1)&lt;BR /&gt;nds = arcpy.GetParameterAsText(3)&lt;BR /&gt;nd_layer_name = "Routing_ND"&lt;BR /&gt;input_facilities = arcpy.GetParameterAsText(4)&lt;BR /&gt;Scratch = arcpy.GetParameterAsText(2)&lt;BR /&gt;SA_ChildCare = Scratch + "/SA_ChildCare"&lt;BR /&gt;SA_CCLoc_Final = Scratch + "/SA_ChildCare_Final"&lt;BR /&gt;people = arcpy.GetParameterAsText(5)&lt;BR /&gt;people_pt = gdb + "/Boundary/people_pt"&lt;BR /&gt;SA_Population = Scratch + "/SA_Population"&lt;BR /&gt;SA_PopLoc_Final = Scratch + "/SA_Population_Final"&lt;BR /&gt;CC_Pop_Inter = Scratch + "/cc_pop_i"&lt;BR /&gt;ChildCare_Summary = Scratch + "/cc_sum"&lt;BR /&gt;CC_Pop_Sum = Scratch + "/cc_pop_sum"&lt;BR /&gt;E2SFCA_temp = Scratch + "/E2SFCA_temp"&lt;BR /&gt;DA_Summary = Scratch + "/DA_sum"&lt;BR /&gt;E2SFCA = gdb + "/FinalAnalysis/E2SFCA"&lt;BR /&gt;Z_Summary = Scratch + "/Z_Summary"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;BR /&gt;m = aprx.listMaps(arcpy.GetParameter(5))[0]&lt;BR /&gt;lyt = &lt;SPAN style="background-color: #f6f6f6;"&gt;aprx.listLayouts(&lt;/SPAN&gt;arcpy.GetParameter(6))[0]&lt;/P&gt;&lt;P&gt;lyrfile = arcpy.GetParameter(7)&lt;BR /&gt;m.addLayer(lyrfile)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Here is the parameters:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/453554_pastedImage_2.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 18 Jul 2019 22:25:14 GMT</pubDate>
    <dc:creator>AndrewClark2</dc:creator>
    <dc:date>2019-07-18T22:25:14Z</dc:date>
    <item>
      <title>How do I add feature layers to map through python?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-add-feature-layers-to-map-through-python/m-p/29811#M2321</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am working in ArcGIS Pro 2.4. I am trying to create map layouts automatically through a Python Tool, which is located in a toolbox. I have been able to create this in Jupyter but&amp;nbsp;the people that will be running the tool do not have access to the software. I have the following code at the moment:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;BR /&gt;m = aprx.listMaps("Map")[0]&lt;BR /&gt;lyt = aprx.listLayouts("Child Care Need Index")[0]&lt;/P&gt;&lt;P&gt;lyrfile = arcpy.mp.LayerFile(path + "/LayerFiles/Neighbourhoods.lyrx")&lt;BR /&gt;m.addDataFromPath(lyrfile)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;It runs perfectly if I copy and paste it into the python window, but as soon as I try to run it through the toolbox I get the following error message:&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt; File "C:\users\*****\appdata\local\temp\arcgisprotemp11624\mapping.py", line 32, in &amp;lt;module&amp;gt;&lt;BR /&gt; m.addDataFromPath(lyrfile)&lt;BR /&gt; File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\_mp.py", line 1531, in addDataFromPath&lt;BR /&gt; return convertArcObjectToPythonObject(self._arc_object.addDataFromPath(*gp_fixargs((data_path,), True)))&lt;BR /&gt;RuntimeError&lt;BR /&gt; Failed to execute (Script1).&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Any ideas on what I am doing wrong?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jul 2019 03:29:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-add-feature-layers-to-map-through-python/m-p/29811#M2321</guid>
      <dc:creator>AndrewClark2</dc:creator>
      <dc:date>2019-07-18T03:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add feature layers to map through python?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-add-feature-layers-to-map-through-python/m-p/29812#M2322</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;what is 'path'?&lt;/P&gt;&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #f6f6f6; color: #3d3d3d; font-family: inherit; font-size: 100%; font-style: inherit; font-variant: normal; font-weight: inherit; letter-spacing: normal; orphans: 2; overflow-wrap: break-word; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;path + "/LayerFiles/Neighbourhoods.lyrx")&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jul 2019 08:56:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-add-feature-layers-to-map-through-python/m-p/29812#M2322</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2019-07-18T08:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add feature layers to map through python?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-add-feature-layers-to-map-through-python/m-p/29813#M2323</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just the location of my layer file that I define earlier.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jul 2019 12:14:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-add-feature-layers-to-map-through-python/m-p/29813#M2323</guid>
      <dc:creator>AndrewClark2</dc:creator>
      <dc:date>2019-07-18T12:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add feature layers to map through python?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-add-feature-layers-to-map-through-python/m-p/29814#M2324</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Andrew, so can we assume that you imported arcpy?&amp;nbsp; You say the people don't have the software.... what software are they missing? Pro?&amp;nbsp; Jupyter?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jul 2019 19:31:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-add-feature-layers-to-map-through-python/m-p/29814#M2324</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2019-07-18T19:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add feature layers to map through python?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-add-feature-layers-to-map-through-python/m-p/29815#M2325</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes I imported arcpy. It doesn't matter what they are missing... sorry that was useless details regarding my issue. I am just trying to make my tool as "idiot proof" as possible, which requires to create a standalone toolbox that uses a syntax to create preset maps from existing data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This exact code works when I use Jupyter, but when I try to create a python script tool for a toolbox I am creating in ArcGIS PRO the same code no longer works. I can even run it in the python window in pro and it works fine. I just don't understand why it crashes when using a toolbox vs the other two methods of running code.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jul 2019 19:44:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-add-feature-layers-to-map-through-python/m-p/29815#M2325</guid>
      <dc:creator>AndrewClark2</dc:creator>
      <dc:date>2019-07-18T19:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add feature layers to map through python?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-add-feature-layers-to-map-through-python/m-p/29816#M2326</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That leads me to believe that it is the parameters of the toolbox.&amp;nbsp; If you created a conventional toolbox,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://pro.arcgis.com/en/pro-app/arcpy/geoprocessing_and_python/a-quick-tour-of-creating-script-tools.htm" title="https://pro.arcgis.com/en/pro-app/arcpy/geoprocessing_and_python/a-quick-tour-of-creating-script-tools.htm"&gt;What is a script tool?—Geoprocessing and Python | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then the problem may be with the toolbox itself or how the parameters (or lack of them) are defined for the toolbox.&lt;/P&gt;&lt;P&gt;If you are using a python toolbox (*.pyt) then there is a load more you have to handle.&lt;/P&gt;&lt;P&gt;Although somewhat dated, the principles described here are largely the same&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/blogs/dan_patterson/2016/05/19/toolbox-creation-in-arcgis-pro"&gt;/blogs/dan_patterson/2016/05/19/toolbox-creation-in-arcgis-pro&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To make it easier for the user, you can set Defaults and provide Value lists for user selection.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jul 2019 19:58:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-add-feature-layers-to-map-through-python/m-p/29816#M2326</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2019-07-18T19:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add feature layers to map through python?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-add-feature-layers-to-map-through-python/m-p/29817#M2327</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Dan!!! I got it working. Here is the full syntax and parameters:&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;import arcpy, os&lt;BR /&gt;arcpy.CheckOutExtension("network")&lt;/P&gt;&lt;P&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;path = arcpy.GetParameterAsText(0)&lt;BR /&gt;gdb = arcpy.GetParameterAsText(1)&lt;BR /&gt;nds = arcpy.GetParameterAsText(3)&lt;BR /&gt;nd_layer_name = "Routing_ND"&lt;BR /&gt;input_facilities = arcpy.GetParameterAsText(4)&lt;BR /&gt;Scratch = arcpy.GetParameterAsText(2)&lt;BR /&gt;SA_ChildCare = Scratch + "/SA_ChildCare"&lt;BR /&gt;SA_CCLoc_Final = Scratch + "/SA_ChildCare_Final"&lt;BR /&gt;people = arcpy.GetParameterAsText(5)&lt;BR /&gt;people_pt = gdb + "/Boundary/people_pt"&lt;BR /&gt;SA_Population = Scratch + "/SA_Population"&lt;BR /&gt;SA_PopLoc_Final = Scratch + "/SA_Population_Final"&lt;BR /&gt;CC_Pop_Inter = Scratch + "/cc_pop_i"&lt;BR /&gt;ChildCare_Summary = Scratch + "/cc_sum"&lt;BR /&gt;CC_Pop_Sum = Scratch + "/cc_pop_sum"&lt;BR /&gt;E2SFCA_temp = Scratch + "/E2SFCA_temp"&lt;BR /&gt;DA_Summary = Scratch + "/DA_sum"&lt;BR /&gt;E2SFCA = gdb + "/FinalAnalysis/E2SFCA"&lt;BR /&gt;Z_Summary = Scratch + "/Z_Summary"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;BR /&gt;m = aprx.listMaps(arcpy.GetParameter(5))[0]&lt;BR /&gt;lyt = &lt;SPAN style="background-color: #f6f6f6;"&gt;aprx.listLayouts(&lt;/SPAN&gt;arcpy.GetParameter(6))[0]&lt;/P&gt;&lt;P&gt;lyrfile = arcpy.GetParameter(7)&lt;BR /&gt;m.addLayer(lyrfile)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Here is the parameters:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/453554_pastedImage_2.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jul 2019 22:25:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-add-feature-layers-to-map-through-python/m-p/29817#M2327</guid>
      <dc:creator>AndrewClark2</dc:creator>
      <dc:date>2019-07-18T22:25:14Z</dc:date>
    </item>
  </channel>
</rss>

