<?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: Using Trace by AH Attributes from Python in Water Resources Questions</title>
    <link>https://community.esri.com/t5/water-resources-questions/using-trace-by-ah-attributes-from-python/m-p/1270959#M4324</link>
    <description>&lt;P&gt;Glad it worked.&lt;/P&gt;</description>
    <pubDate>Thu, 23 Mar 2023 16:23:15 GMT</pubDate>
    <dc:creator>DeanDjokic</dc:creator>
    <dc:date>2023-03-23T16:23:15Z</dc:date>
    <item>
      <title>Using Trace by AH Attributes from Python</title>
      <link>https://community.esri.com/t5/water-resources-questions/using-trace-by-ah-attributes-from-python/m-p/1269289#M4315</link>
      <description>&lt;P&gt;Good day,&lt;/P&gt;&lt;P&gt;I'm exploring using Arc Hydro's&amp;nbsp;Trace by AH Attributes tool in a Python script as an alternative to ArcGIS Pro's built-in Trace tool. Following is our test script:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; arcpy&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; tracebyahattributes&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;arcpy.MakeFeatureLayer_management(&lt;/SPAN&gt;&lt;SPAN&gt;'C:/GIS/test/PBF2.gdb/CWFHydrology3'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'hydro_lyr'&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;flags = &lt;/SPAN&gt;&lt;SPAN&gt;'C:/GIS/test/PBF2.gdb/Flag'&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;barriers = &lt;/SPAN&gt;&lt;SPAN&gt;'C:/GIS/test/PBF2.gdb/AllOthers'&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;tracebyahattributes.traceviaAttributesAH(in_points=flags, in_streams=&lt;/SPAN&gt;&lt;SPAN&gt;'hydro_lyr'&lt;/SPAN&gt;&lt;SPAN&gt;, trace_direction=&lt;/SPAN&gt;&lt;SPAN&gt;'Upstream'&lt;/SPAN&gt;&lt;SPAN&gt;, search_distance=&lt;/SPAN&gt;&lt;SPAN&gt;'50'&lt;/SPAN&gt;&lt;SPAN&gt;, max_next_lines=&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;, in_barriers=barriers)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;print(arcpy.GetCount_management(&lt;/SPAN&gt;&lt;SPAN&gt;'hydro_lyr'&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Unlike running the tool interactively, I cannot seem to get the selected hydrology segments (it does not make a selection on the passed hydro_lyr)! Is this tool only intended to be run in an interactive ArcGIS Pro session, or is there is something else that can be done to get the selected hydrology segments in the script?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Thanks in advance,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Randal&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 19 Mar 2023 20:48:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/water-resources-questions/using-trace-by-ah-attributes-from-python/m-p/1269289#M4315</guid>
      <dc:creator>RandalGreene3</dc:creator>
      <dc:date>2023-03-19T20:48:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using Trace by AH Attributes from Python</title>
      <link>https://community.esri.com/t5/water-resources-questions/using-trace-by-ah-attributes-from-python/m-p/1269985#M4316</link>
      <description>&lt;P&gt;Randal - which version of Pro and Arc Hydro tools are you using?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 18:16:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/water-resources-questions/using-trace-by-ah-attributes-from-python/m-p/1269985#M4316</guid>
      <dc:creator>DeanDjokic</dc:creator>
      <dc:date>2023-03-21T18:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using Trace by AH Attributes from Python</title>
      <link>https://community.esri.com/t5/water-resources-questions/using-trace-by-ah-attributes-from-python/m-p/1270001#M4317</link>
      <description>&lt;P&gt;Hi Dean,&lt;/P&gt;&lt;P&gt;I'm using ArcGIS Pro 3.1 and the latest ArcHydroToolsforArcGISPro3.msi download. I could potentially try with earlier versions of either on another machine if you think it might be helpful.&lt;/P&gt;&lt;P&gt;Thanks very much,&lt;/P&gt;&lt;P&gt;Randal&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 18:47:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/water-resources-questions/using-trace-by-ah-attributes-from-python/m-p/1270001#M4317</guid>
      <dc:creator>RandalGreene3</dc:creator>
      <dc:date>2023-03-21T18:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using Trace by AH Attributes from Python</title>
      <link>https://community.esri.com/t5/water-resources-questions/using-trace-by-ah-attributes-from-python/m-p/1270011#M4318</link>
      <description>&lt;P&gt;Thanks.&amp;nbsp; No need to switch - we are looking at the code and wanted to make sure we are looking at the right version.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 19:06:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/water-resources-questions/using-trace-by-ah-attributes-from-python/m-p/1270011#M4318</guid>
      <dc:creator>DeanDjokic</dc:creator>
      <dc:date>2023-03-21T19:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: Using Trace by AH Attributes from Python</title>
      <link>https://community.esri.com/t5/water-resources-questions/using-trace-by-ah-attributes-from-python/m-p/1270725#M4321</link>
      <description>&lt;P&gt;Randal,&lt;/P&gt;&lt;P&gt;We have updated the code for the Trace by AH Attributes to make it more Arc Hydro-ish with respect to how it is called from python.&amp;nbsp; Please install AH version 3.0.58 (of course, uninstall the previous version first).&lt;/P&gt;&lt;P&gt;Your updated code should then look something like (you can type this on the python command line and replace with proper pointers to your data – if it works, then move to your code):&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;import hydroconfig&lt;/P&gt;&lt;P&gt;import tracebyahattributes&lt;/P&gt;&lt;P&gt;in_flags = "D:\\10Data\\Raindrop2022\\AH2022.gdb\\Trace_by_AH_Attributes_Input_Start_Points_Points_3"&lt;/P&gt;&lt;P&gt;in_barriers = None&lt;/P&gt;&lt;P&gt;in_streams = "DrainageLine"&lt;/P&gt;&lt;P&gt;trace_direction = 'Upstream'&amp;nbsp; #or 'Downstream', 'Both'&lt;/P&gt;&lt;P&gt;search_distance = 50&lt;/P&gt;&lt;P&gt;max_next_lines = 0&amp;nbsp;&amp;nbsp;&amp;nbsp; #0=all, 1, 2, 3, =first, first 2, first 3 line(s) when there are splits&lt;/P&gt;&lt;P&gt;exclude_start_elements = False&amp;nbsp; #..start elements would be included in the results (elements a flag hits)&lt;/P&gt;&lt;P&gt;p = tracebyahattributes.TraceByAHAttributes()&lt;/P&gt;&lt;P&gt;p.DebugLevel = 1&lt;/P&gt;&lt;P&gt;t_returns = p.executeAH(in_flags, in_streams, trace_direction, search_distance, max_next_lines, in_barriers, exclude_start_elements)&lt;/P&gt;&lt;P&gt;if(t_returns[0] == hydroconfig.C_OK):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print(t_returns)&lt;/P&gt;&lt;P&gt;else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(t_returns[0])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-------- to try on the python command line after successful trace run&lt;/P&gt;&lt;P&gt;print(t_returns)&lt;/P&gt;&lt;P&gt;('OK', '36,31,32,25,26,27,30,21,22,18,19,23,24,16,17,14,15,3,4,11,13,1,2,12,20,9,10,5,6,7,8', 'ts_results', 'ts_start_points', '36', None)&lt;/P&gt;&lt;P&gt;Several things to note:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;t_returns – this is the “result” that the function returns.&amp;nbsp; It consists of several elements.&lt;UL&gt;&lt;LI&gt;Fist element (index 0) is whether the function completed successfully.&amp;nbsp; If it is “OK” then it finished correctly and the following elements in the list are individual results.&lt;/LI&gt;&lt;LI&gt;Second element is a string containing a comma delimited list of ArcIDs that are the trace results.&amp;nbsp; This can be useful if you are running the script “headless” – e.g. outside of Pro (pure python).&lt;/LI&gt;&lt;LI&gt;Third element is feature set of returned lines ( -- I think you are looking for this --)&lt;/LI&gt;&lt;LI&gt;Fourth element is feature set of input flags (starting points)&lt;/LI&gt;&lt;LI&gt;Fifth element is the count of returned trace lines ( -- I think you are looking for this --)&lt;/LI&gt;&lt;LI&gt;Sixth element is feature set of barriers if any were used.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;This should return a selected set if you are running your code from within Pro.&lt;/LI&gt;&lt;LI&gt;Using this function makes sense if you have simple “network” and want basic upstream/downstream trace analysis.&amp;nbsp; You should use trace network if the trace system is more complex (e.g. multiple layers, complex edges, …).&amp;nbsp; We use TN for stormwater analysis within Arc Hydro.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Let me know if this works for you.&lt;/P&gt;&lt;P&gt;Also, please review document "Arc Hydro - Calling Arc Hydro Tools in Python.pdf" (&lt;A href="https://community.esri.com/t5/water-resources-documents/arc-hydro-calling-arc-hydro-tools-in-python-pdf/ta-p/920821" target="_blank"&gt;https://community.esri.com/t5/water-resources-documents/arc-hydro-calling-arc-hydro-tools-in-python-pdf/ta-p/920821&lt;/A&gt;).&amp;nbsp; It goes into more detail on accessing AH functions through python script.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 04:54:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/water-resources-questions/using-trace-by-ah-attributes-from-python/m-p/1270725#M4321</guid>
      <dc:creator>DeanDjokic</dc:creator>
      <dc:date>2023-03-23T04:54:49Z</dc:date>
    </item>
    <item>
      <title>Re: Using Trace by AH Attributes from Python</title>
      <link>https://community.esri.com/t5/water-resources-questions/using-trace-by-ah-attributes-from-python/m-p/1270820#M4322</link>
      <description>&lt;P&gt;Brilliant, works like a charm! Thanks very much for the quick turnaround.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 11:55:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/water-resources-questions/using-trace-by-ah-attributes-from-python/m-p/1270820#M4322</guid>
      <dc:creator>RandalGreene3</dc:creator>
      <dc:date>2023-03-23T11:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using Trace by AH Attributes from Python</title>
      <link>https://community.esri.com/t5/water-resources-questions/using-trace-by-ah-attributes-from-python/m-p/1270959#M4324</link>
      <description>&lt;P&gt;Glad it worked.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 16:23:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/water-resources-questions/using-trace-by-ah-attributes-from-python/m-p/1270959#M4324</guid>
      <dc:creator>DeanDjokic</dc:creator>
      <dc:date>2023-03-23T16:23:15Z</dc:date>
    </item>
  </channel>
</rss>

