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,
result_name,
flags,
'FIND_CONNECTED'
)
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.
out_network_layerthat 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 01 '16 at 11:07AssertionError. When I addedresult = arcpy.mapping.Layer(result)beforearcpy.mapping.AddLayer(df, result, "BOTTOM"), I getTypeError: <class arcpy.arcobjects.arcobjects.Result>– General Failure Feb 01 '16 at 11:22import arcpyand includesarcpy.mapping.AddLayer(). – PolyGeo Feb 01 '16 at 11:53