<?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 to add Route Layer to Map using Arcpy.nax, Pro 2.5? in ArcGIS Network Analyst Questions</title>
    <link>https://community.esri.com/t5/arcgis-network-analyst-questions/how-to-add-route-layer-to-map-using-arcpy-nax-pro/m-p/754864#M7233</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The second one worked - thanks for your help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 11 Aug 2020 17:54:57 GMT</pubDate>
    <dc:creator>jacquelinewillan1</dc:creator>
    <dc:date>2020-08-11T17:54:57Z</dc:date>
    <item>
      <title>How to add Route Layer to Map using Arcpy.nax, Pro 2.5?</title>
      <link>https://community.esri.com/t5/arcgis-network-analyst-questions/how-to-add-route-layer-to-map-using-arcpy-nax-pro/m-p/754860#M7229</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What is the best way to generate a route, that can be saved as a route, and displayed on the map, using Pro 2.5? I created a route using the arcpy.nax module (which I found is faster than using the arcpy.na to Make a Route Analysis Layer), and was able to save as a layer file:&lt;/P&gt;&lt;P&gt;routeLyr = result.saveAsLayerFile(WorkSpace + os.path.sep +&amp;nbsp; RouteName + ".lyr"), but then I want to add it to the map and choose the colors. When I tried the code below, I got an error: on the line for the mp.LayerFile:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;curPrj = arcpy.mp.ArcGISProject("CURRENT")&lt;BR /&gt; curMap = curPrj.listMaps("*")[0]&lt;/P&gt;&lt;P&gt;layerPath = WS + os.path.sep + RouteName + ".lyr"&lt;BR /&gt;lf = arcpy.mp.LayerFile(layerPath)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also tried:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;lf = arcpy.mp.LayerFile(routeLyr&amp;nbsp;), but got an error for that too.&amp;nbsp; In 10.6 my users liked the fact that they could generate some routes and then go back later and add barriers, and to do that I can't just export the route to a feature class. Is there an alternate method to save/export the route?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any help on how to use python to display the layer or an alternate way to save/export a route would be greatly appreciated!&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Aug 2020 21:41:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-network-analyst-questions/how-to-add-route-layer-to-map-using-arcpy-nax-pro/m-p/754860#M7229</guid>
      <dc:creator>jacquelinewillan1</dc:creator>
      <dc:date>2020-08-10T21:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to add Route Layer to Map using Arcpy.nax, Pro 2.5?</title>
      <link>https://community.esri.com/t5/arcgis-network-analyst-questions/how-to-add-route-layer-to-map-using-arcpy-nax-pro/m-p/754861#M7230</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm guessing from your questions that you are writing a python script tool that you intend to run as a geoprocessing tool within ArcGIS Pro.&amp;nbsp; Is this correct?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If this is the case, then the proper way to add the output network analysis layer to the map is not to use the mapping module to add it explicitly but to simply add an output parameter to the script tool.&amp;nbsp; Let me explain further.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, when setting up your tool parameters in the tool dialog, create an output parameter.&amp;nbsp; Set the type to Network Analysis Layer.&amp;nbsp; Make a note of the index for this parameter.&amp;nbsp; You can also set up a symbology layer for this parameter.&amp;nbsp; By specifying a symbology layer here, it will automatically apply this layer's symbology to the derived output when it adds it to the map.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you run the tool, it should automatically add the layer to the map.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you don't want the users of your tool to specify the path to the output .lyr file, but instead you want to handle that internally, you can make the parameter definition of type "Derived".&amp;nbsp;&amp;nbsp;In the script, once you have your output layer path, assign the layer to that parameter using arcpy.SetParameter().&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note: if your ultimate goal is to create fully-functioning network analysis layers as the output of your tool, the arcpy.nax module might not be the right choice.&amp;nbsp; It might be better to use the classic Make Route Analysis Layer, Add Locations, Solve workflow.&amp;nbsp; The saveAsLayerFile() method for the nax solver objects is primarily meant for debugging.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Aug 2020 23:15:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-network-analyst-questions/how-to-add-route-layer-to-map-using-arcpy-nax-pro/m-p/754861#M7230</guid>
      <dc:creator>MelindaMorang</dc:creator>
      <dc:date>2020-08-10T23:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to add Route Layer to Map using Arcpy.nax, Pro 2.5?</title>
      <link>https://community.esri.com/t5/arcgis-network-analyst-questions/how-to-add-route-layer-to-map-using-arcpy-nax-pro/m-p/754862#M7231</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes I am&amp;nbsp;&lt;SPAN style="background-color: #ffffff;"&gt;writing a python script tool that&amp;nbsp;will be run as a geoprocessing tool within ArcGIS Pro. What you suggest sounds like that might be what I need. I had tried&amp;nbsp;&lt;SPAN&gt;creating an output parameter of type Network Analysis Layer (with Type Derived, Direction Output), but at that point I didn't know how to get it to be added to the map (in 10.6 I had used the derived parameter and it was automatically added to the Table of Contents - and random symbology). When I tried it in Pro, it was not automatically added to the Table of Contents, so I was trying other ways to implement it. I do want it handled internally. I'm not clear on the line of code for specifying the output layer path would that be like:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;&lt;SPAN&gt;RouteLyr = arcpy.SetParameter(5,"D:\myDir") with 5 being the index of the parameter? Would I also put the name like:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;&lt;SPAN&gt;"D:\myDir\Route.lyrx"? I tried the line without the lyrx name and there was no error, but when I tried the next line:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;&lt;SPAN&gt;lyrFile = arcpy.mp.LayerFile(RouteLyr) I get an error message:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;&lt;SPAN&gt;TypeError: Required argument 'layer_file_path' (pos 1) not found&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;&lt;SPAN&gt;What am I missing?&amp;nbsp; Thanks for your help!&amp;nbsp; I'd rather not use the&amp;nbsp;Make Route Analysis Layer method because it took much longer and my users are used to performing a Solve in a few seconds not waiting 25-some seconds for the&amp;nbsp;Make Route Analysis Layer, Add Locations, and Solve. Thanks!&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="" style="color: #333333; background-color: #ffffff; font-size: 12.96px; padding: 0px 0px 0.25rem;"&gt;&lt;SPAN class="" style="color: #de2900; background-color: #ffffff; text-decoration: none; padding: 0px 0px 0.25rem;"&gt;ValueError: Route&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Aug 2020 23:54:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-network-analyst-questions/how-to-add-route-layer-to-map-using-arcpy-nax-pro/m-p/754862#M7231</guid>
      <dc:creator>jacquelinewillan1</dc:creator>
      <dc:date>2020-08-10T23:54:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to add Route Layer to Map using Arcpy.nax, Pro 2.5?</title>
      <link>https://community.esri.com/t5/arcgis-network-analyst-questions/how-to-add-route-layer-to-map-using-arcpy-nax-pro/m-p/754863#M7232</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try something like this:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;layer_path &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"D:\myDir\Route.lyr"&lt;/SPAN&gt;
result&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;saveAsLayerFile&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;layer_path&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SetParameterAsText&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;5&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; layer_path&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;I'm not 100% sure if that will work.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;There are a couple of things to be aware of with regards to the nax solver objects as saveAsLayerFile.&amp;nbsp; First, the saved layer file is a .lyr file in the old ArcMap style,&amp;nbsp;&lt;EM&gt;not&lt;/EM&gt; a .lyrx in the Pro style.&amp;nbsp; If you try to use .lyrx in the output path, it will fail.&amp;nbsp; You must use .lyr.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;Since the output file is a .lyr file, I don't know if it will actually work with SetParameter() or SetParameterAsText() because that might be expecting a Pro-style layer file or layer object.&amp;nbsp; As I said, the intention of these saved layer files from the nax solver objects is for debugging, not for what you're currently doing.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;Another thing you could try is reconstituting the layer file as a Pro-style layer object after you've saved it out.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;layer_path &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"D:\myDir\Route.lyr"&lt;/SPAN&gt;
result&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;saveAsLayerFile&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;layer_path&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
layer_object &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;LayerFile&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;layer_path&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;listLayers&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;SetParameter&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;5&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; layer_object&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't know if that will work either, though.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:01:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-network-analyst-questions/how-to-add-route-layer-to-map-using-arcpy-nax-pro/m-p/754863#M7232</guid>
      <dc:creator>MelindaMorang</dc:creator>
      <dc:date>2021-12-12T08:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to add Route Layer to Map using Arcpy.nax, Pro 2.5?</title>
      <link>https://community.esri.com/t5/arcgis-network-analyst-questions/how-to-add-route-layer-to-map-using-arcpy-nax-pro/m-p/754864#M7233</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The second one worked - thanks for your help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Aug 2020 17:54:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-network-analyst-questions/how-to-add-route-layer-to-map-using-arcpy-nax-pro/m-p/754864#M7233</guid>
      <dc:creator>jacquelinewillan1</dc:creator>
      <dc:date>2020-08-11T17:54:57Z</dc:date>
    </item>
  </channel>
</rss>

