Select to view content in your preferred language

Python cannot "see" output from geometric trace.

1883
8
04-19-2017 09:36 AM
by Anonymous User
Not applicable

I have a python based tool that is error-ing out at the point where it needs to access the output of a geometric trace:

# Process: Trace Geometric Network
arcpy.AddMessage("> Downstream Trace...")
down_tg = "DOWNSTREAM_TRACE_GROUP"
arcpy.TraceGeometricNetwork_management(Geometric_Network, down_tg, poe_copy, \
"TRACE_DOWNSTREAM", "", "", "", "", "", "NO_TRACE_ENDS", "NO_TRACE_INDETERMINATE_FLOW", \
"", "", "AS_IS", "", "", "", "AS_IS")

#Process: Try to prevent CPs from snapping to junctions.
currmxd.save()
down_trace = down_tg+r"\NHN_HN_PrimaryDirectedNLFow_1"

arcpy.AddMessage("> Modifying downstream trace to minimize junction-snapping...")
out_verts = "in_memory\\out_verts"

 arcpy.FeatureVerticesToPoints_management(down_trace, out_verts,"BOTH_ENDS")

Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset DOWNSTREAM_TRACE_GROUP\NHN_HN_PrimaryDirectedNLFow_1 does not exist or is not supported
Failed to execute (FeatureVerticesToPoints).

DOWNSTREAM_TRACE_GROUP\NHN_HN_PrimaryDirectedNLFow_1 DOES EXIST!  It has been created!

After I get this error, I can run a tool from the toolbox - for example "Copy Features" and I can see "GeometricNetwork\NHN_HN_PrimaryDirectedNLFow_1" in the drop down, I can select it, and I can create an output.

But Python simply cannot see it.

In the python window within the mxd, if I list layers, I cannot see this group layer ("GeometricNetwork"), but if I select the python snippet from the copy features tool above and simply paste it in, it runs fine with the reference to "GeometricNetwork\NHN_HN_PrimaryDirectedNLFow_1" right there in the code line.

I ran the geometric trace as a tool and the output ends up in my TOC just fine.

I ran it as a model and selected "Add to Display" on the green egg output symbol.

Perfectly fine.

Python simply refuses to see this output. It is not getting added to the mxd. I tried to create a layer, but I can't do that because no tool will recognize the initial output from the trace tool.

Any idea how to get python to acknowledge the existence of this output?

 

The attached picture shows the visible "DOWNSTREAM_TRACE_GROUP" and the output layer that Python just claimed didn't exist.

Thank you very much.

Randy McGregor

0 Kudos
8 Replies
IanMurray
Honored Contributor

Have you set your environmental variables so it auto adds the output of Geoprocessing operations to the map?

http://pro.arcgis.com/en/pro-app/arcpy/classes/env.htm

arcpy.env.addOutputsToMap = True

0 Kudos
by Anonymous User
Not applicable

I have not.

I have that set in “Geoprocessing Options” but I haven’t set an environment for this. I never have before.

Thanks for the suggestion. I’ll see if that helps.

Randy McGregor | GIS Analyst

(612) 227-3147 – Cell | @ddmsinc<https://twitter.com/ddmsinc> | www.ddmsinc.com<http://www.ddmsinc.com/>

0 Kudos
IanMurray
Honored Contributor

That would be the first place I would go since it was not adding the output to your map document when run as a python tool(which I'm assuming you are running within the MXD in questions).  Once we know for sure that the group layer is added to the map document, and if python still cannot recognize the local path within the map document for that layer within the group layer, then you will likely need to create a layer object for that layer and use that for the input for the tool.

http://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-mapping/layer-class.htm

0 Kudos
by Anonymous User
Not applicable

I have tried to create a layer, but since the output of the trace is unrecognized by python, I am stuck. Create Layer, Add Layer, Save as Layer File, etc... all error out because I can't provide any input to them that they can see.

0 Kudos
IanMurray
Honored Contributor

Did it actually add the layers to the map once you added the environment variable I mentioned before?

I wasn't saying create a new layer, but once the group layer is created in the map document, you should be able to list all the layers in the map document in arcpy and create a layer object in python referencing that layer in the map.  I'm not 100% sure but you should then be able to use that Layer object as the input for Feature to Vertices.

That doesn't answer the larger question of why a perfectly valid python tool was working with a one dataset and not another though.

by Anonymous User
Not applicable

Actually, I ended up adding the output GROUP (trace output is a group layer) so that is when I saw that the line layer was incorrectly named.

The group layer could be saved as a .lyr file, no problem. It just died when I tried to access the misnamed line file.

So, thank you VERY much for your help.

Randy McGregor | GIS Analyst

(612) 227-3147 – Cell | @ddmsinc<https://twitter.com/ddmsinc> | www.ddmsinc.com<http://www.ddmsinc.com/>

0 Kudos
by Anonymous User
Not applicable

OK, this is officially the most frustrating error in the history of GIS.

When I load the geometric network in, the linear features are called "NHN_HN_PrimaryDirectedNLFow_1"

That is the name of the layer as it appears in the TOC when added, and I assumed it was the name of the feature class itself. Who would chose to give a layer a name like that?! (Answer nobody, this is a typo)

The actual feature class ls called NHN_HN_PrimaryDirectedNLFlow_1 (Note the extra "l" ... "Flow" (Makes sense)).

That is the name given to the trace output - based on the feature class name (not the layer name)  but I had plugged in the LAYER NAME into the python script, which kept not finding a layer by that name (for three days ).

Time to re-introduce myself to my family who think I've gone crazy. Maybe shave, eat something, take a shower...

0 Kudos
by Anonymous User
Not applicable

Thanks but that didn't fix it. Good suggestion.

I have run the tool successfully with NHD data, but it is doing this to me with NHN (Canada's Networked Hydrology Data). I took a script that worked with NHD, tweaked it just to change the name of the geometric network - no other change - and I get this error.

I don't know why, but the NHN data seems to be causing this problem...

0 Kudos