How do I access the resultant group layer of a Trace Geometric Network from an Add-In?

2887
1
08-15-2015 10:28 AM
DamienHigh
New Contributor

I'm trying to write an Add-In to ArcMap that will allow users to perform traces on a geometric network and symbolise features linked to affected portions of the network.

The user clicks on the network to specify a flag and the script carries out a trace with a predefined feature class of barriers to find out the immediately isolated network. The script then successfully exports the results of this trace from the resultant group layer to a new feature class.

My problem lies accessing the results of the next trace on the geometric network from the Add-In. The next trace should identify affected elements based on the isolation from the first trace. This second trace works fine and the resultant group layer is displayed in the table of contents with expected elements of the network selected. However, I cannot access the selected features in my script to then export the affected network to a new feature class. Manually exporting from within ArcMap works fine, but exporting from the script returns the entire network - not the selection.

I've tried specifying the name of the resultant group layer in the script and then accessing the sublayer with the selection, but the portion of code after the IF statements doesn't trigger which suggests that the group layer is somehow invisible to the script.

Does anybody have any ideas?

Thanks in advance.

0 Kudos
1 Reply
JessicaHanscom
New Contributor II

I just solved a similar issue for myself.  Maybe what I came up with can help you.  Basically I cycle through all the trace result layers added to the map that are prefixed by the group name I added them to the map as.  If you deal with them as a map layer it should honor the selection in whatever you want to do with it. Below is part of my code to write "switch section" data to all feature classes that isolated by switches or open points.  It might be amateurish but it seems to work.

arcpy.TraceGeometricNetwork_management (network, "result_set", "current_switch", "TRACE_DOWNSTREAM","switch_barriers","","","","","","TRACE_INDETERMINATE_FLOW")
            addLayer = arcpy.mapping.Layer("result_set")
            arcpy.mapping.AddLayer(df, addLayer)

            layers = arcpy.mapping.ListLayers(df)
            for l in layers:
                if l.longName[:11] == 'result_set\\' and l.name != 'Electric_Net_Junctions':
                    arcpy.AddMessage('Writing new switch section data (' + str(switchID) + ') on to layer ' + l.longName + '...')
                    lyr = arcpy.mapping.Layer(l.longName)
                    with arcpy.da.UpdateCursor(lyr, ['gs_sw_section']) as cursor:
                        for row in cursor:
                            row[0] = switchID
                            cursor.updateRow(row)

0 Kudos