Randal,
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. Please install AH version 3.0.58 (of course, uninstall the previous version first).
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):
import arcpy
import hydroconfig
import tracebyahattributes
in_flags = "D:\\10Data\\Raindrop2022\\AH2022.gdb\\Trace_by_AH_Attributes_Input_Start_Points_Points_3"
in_barriers = None
in_streams = "DrainageLine"
trace_direction = 'Upstream' #or 'Downstream', 'Both'
search_distance = 50
max_next_lines = 0 #0=all, 1, 2, 3, =first, first 2, first 3 line(s) when there are splits
exclude_start_elements = False #..start elements would be included in the results (elements a flag hits)
p = tracebyahattributes.TraceByAHAttributes()
p.DebugLevel = 1
t_returns = p.executeAH(in_flags, in_streams, trace_direction, search_distance, max_next_lines, in_barriers, exclude_start_elements)
if(t_returns[0] == hydroconfig.C_OK):
print(t_returns)
else:
print(t_returns[0])
-------- to try on the python command line after successful trace run
print(t_returns)
('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)
Several things to note:
- t_returns – this is the “result” that the function returns. It consists of several elements.
- Fist element (index 0) is whether the function completed successfully. If it is “OK” then it finished correctly and the following elements in the list are individual results.
- Second element is a string containing a comma delimited list of ArcIDs that are the trace results. This can be useful if you are running the script “headless” – e.g. outside of Pro (pure python).
- Third element is feature set of returned lines ( -- I think you are looking for this --)
- Fourth element is feature set of input flags (starting points)
- Fifth element is the count of returned trace lines ( -- I think you are looking for this --)
- Sixth element is feature set of barriers if any were used.
- This should return a selected set if you are running your code from within Pro.
- Using this function makes sense if you have simple “network” and want basic upstream/downstream trace analysis. You should use trace network if the trace system is more complex (e.g. multiple layers, complex edges, …). We use TN for stormwater analysis within Arc Hydro.
Let me know if this works for you.
Also, please review document "Arc Hydro - Calling Arc Hydro Tools in Python.pdf" (https://community.esri.com/t5/water-resources-documents/arc-hydro-calling-arc-hydro-tools-in-python-...). It goes into more detail on accessing AH functions through python script.