There is a modelbuilder tool called 'Select Data' that pulls a single layer out of a group layer.
I am using Python to do geometric tracing and the outputs are group layers.
Does anyone know the Python equivalent of "Select Data"?
I guess I could cycle through and find the right layer, but if there's an easier way, I'd like to know.
I am assuming there is a (relatively) easy way to do this in Python. Otherwise, it would make no sense to deny Python this handy tool.
Thank you. Yes, I would have to select the group layer output of the "FindPath" tool, then select (in this case) "NHD Flowlines" from the group.
I appreciate the tip. It probably wouldn't be too bad, but I was hoping there would be a single tool available for this.
The help discusses using Select Data with this tool but indeed is missing guidance on how to best go at this in Python: Trace Geometric Network—Help | ArcGIS Desktop
An issue here (mentioned in the tool help) is that group layers are not supported in some environments.
This is especially useful when publishing your model to ArcGIS Server, since group layers are not supported as an output parameter type from a geoprocessing task. Because they aren't supported as direct output, you need to use the Select Data tool to create a single (nongroup) layer for output.
I posted feedback to the help author that they should add some Python guidance to the help page.
We ran into this and the solution was (as Dan suggested) arcpy.mapping.ListLayers run on the group layer output. Below I use a list comphension to get the layer you want by search string
trace_lyr = arcpy.TraceGeometricNetwork_management(...) #Create a Mapping Layer out of the Group Layer glyr = arcpy.mapping.Layer(trace_lyr) # Extract the layer based on a search string tlyr = [lyr for lyr in arcpy.mapping.ListLayers(glyr) if "net" in str(lyr).lower()] # copy out to a feature class arcpy.CopyFeatures_management(tlyr, tfeat)
Dan, sorry I deleted my previous post, as I found the answer in an old email exchange, and you jumped on it too fast!
For future readers, my previous (deleted) post suggested examining the output of the trace geometric networks tool to figure out what to do next:
r = arcpy.TraceGeometricNetwork_management(...) r1 = r.getOutput(0) # get output from result object print(r1) print(repr(r1))
The reason to print both is because sometimes the str() and repr() of an object are different and looking at both can give you a clue what the tool actually returned if you are unsure.
In this case I think you'd get something like "Trace" for str() and '<Group layer geoprocessing object at 239478219821>' for repr()
Thanks for the information.
Having thunk on it over the weekend, I think there is a fairly straightforward solution in Python for my purposes.
With the trace tool, you can set the name of the output layer group.
The layer I am interested in is always (for now) "NHDFlowlines"
So, if I set the name of the output group as, "Downstream_Trace_Group" I can simply run:
I have not tried it, but I'm hoping it'll do the trick.