Select to view content in your preferred language

Add trace barriers in a python toolbox code

643
2
Jump to solution
05-09-2023 11:11 PM
EstherSmith_Dev
Occasional Contributor

Hi UN experts,

I have a need for a trace tool in ArcGIS Pro that updates certain attributes for the features traced. The tool also needs to provide option to the user to choose the trace direction at the start location. I am trying to use barriers to stop the trace going into unwanted directions to force it go only in the selected direction.

I tried to add records to  arcpy.env.scratchWorkspace\\UN_Temp_Barriers using 

arcpy.un.AddTraceLocations(self.un_layer, self.trace_barrier_fc,
"DO_NOT_LOAD_SELECTED_FEATURES", "KEEP_LOCATIONS",
"{} {} # 0.5".format(layer_name, layer_guid),
"FILTER_BARRIER")

However, I get the error below:

ERROR 000725: Output Feature Class: Dataset <location>\\UN_Temp_Barriers already exists.
Failed to execute (AddTraceLocations)

I could reproduce this problem. When I run the tool interactively in ArcGIS Pro using Add Trace Locations tool, it worked as below.

EstherSmith_Dev_0-1683681760616.png

But then when I copied the Python command for the above successful run in the Python window, it gave same error.

So I added,

arcpy.env.overwriteOutput = True

and if fixed the problem for AddTraceLocations. But when I run my tool, after the successful run, it just drops the arcpy.env.scratchWorkspace\\UN_Temp_Barriers table afterwards. Any one knows how I can persist UN_Temp_Barriers table? any arcpy.env value that I need to set?

Cheers,

0 Kudos
1 Solution

Accepted Solutions
MikeMillerGIS
Esri Frequent Contributor
If you want to persist it, why not write it to a gdb, not a scratch workspace?

View solution in original post

0 Kudos
2 Replies
MikeMillerGIS
Esri Frequent Contributor
If you want to persist it, why not write it to a gdb, not a scratch workspace?
0 Kudos
RobertKrisher
Esri Regular Contributor

The scratch workspace is a great idea, since you can re-use the same table within the same session instead of having to recreate it every time your run your tool. If you did want to create a new temp layer each time you ran your tool, I'd recommend you use the memory workspace for the duration of the trace. To do this just use the word "memory" for the workspace path (e.g. "memory\\temp_start_barriers").

0 Kudos