This question already has an answer here:

I have geometric network and try to launch Python script with tracing

gdb = "C:/Users/my_user/Documents/ArcGIS/gn/gn.gdb"
gdb += "/gn/"
geometric_net = gdb + "gn_Net"
flags = gdb + "flags"
result_name = "gn_Net2"

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]

result = arcpy.TraceGeometricNetwork_management(geometric_net,

gl = arcpy.mapping.Layer(result_name)
arcpy.mapping.AddLayer(df, gl, "BOTTOM")

This script do nothing (as I see in ArcMap) - no new group layer in ArcMap, no new layers/feature classes/other instances in current geodatabase.

result variable have some value after last row execution, but I can't determine its type - debugger says thatresult.__class__ returns <class 'arcpy.arcobjects.arcobjects.Result'>, and result returns {geoprocessing server result object} gn_Net2

From documentation I presumed that result is group layer that I must to add to map. But I can't find Arcpy method which can add group layer to map - only layer adding to map or existing group layer (arcpy.mapping.AddLayer).

What really arcpy.TraceGeometricNetwork_management returns? Did I understood correctly that it's group layer? And it's ready for add to ArcMap via arcpy.mapping.AddLayer method?
If no, where is tracing result? How can I see it? What is the arcpy.TraceGeometricNetwork_management result?

Edits: I added

  • ArcMap document (mxd) and data frame (df) getting
  • Group layer adding

to script. I launches my script from ArcMap via toolbox-script object.

Result of my changes is: Group layer adds to ArcMap document, but without found path (no new layer, selectiong or highlighting). Only geometry network and its layers was added. When I run geometry tracing manually with same conditions (Utility Network Analyst - Solve), found way highlights at map.

marked as duplicate by KHibma, Evil Genius, Farid Cheraghi, Community Feb 2 '16 at 5:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • "understood correctly that it's group layer ready for add to ArcMap? If yes, how can I add it?" - it does not matter how you created your group layer, this duplicate describes how to add it to a map using ArcPy. – PolyGeo Feb 1 '16 at 10:57
  • I removed question about group layer adding – General Failure Feb 1 '16 at 11:04
  • The documentation says of out_network_layer that it is "The name of the group layer that will store the results of the trace as a selected set." What happens when you try to add it to your map? If you are trying to do this all from ArcPy, I suggest taking a step back and running your workflow from the tool dialogs in ArcMap to get a better feel for what is happening, before going back to try and automate it. – PolyGeo Feb 1 '16 at 11:07
  • I understood that second parameter is just name. When I launch my script without existing group layer with same name, happings nothing (at least at screen). But when group layer with that name was added manually and then script launched, group layer disappears. Then I suggested that I must get result layer and add it to map manually. – General Failure Feb 1 '16 at 11:13
  • When I tried to add tracing result, I get AssertionError. When I added result = arcpy.mapping.Layer(result) before arcpy.mapping.AddLayer(df, result, "BOTTOM"), I get TypeError: <class arcpy.arcobjects.arcobjects.Result> – General Failure Feb 1 '16 at 11:22