2

I'm attempting to write a python addin to ArcGIS that will carry out numerous traces on a geometric network using user specified flags/barriers.

The first trace works fine and I'm able to access the results of the trace inside the script and export the selected (isolated) network to a new feature class.

    #2.2 Obtain isolation area by tracing geometric network, getting list of isolated pipes and saving selection
    try:
        arcpy.TraceGeometricNetwork_management("Geometric_Model_Net","Network_from_Mains_Pipes","Flags","FIND_CONNECTED","Valves")
        # get gp messages for trace geometric network tool
        print "\n\n*** 2.2.1 TRACE GEOMETRIC NETWORK Geoprocessing Messages***\n"
        print arcpy.GetMessages()
    except arcpy.ExecuteError:
        print "\n\n*** 2.2.1 TRACE GEOMETRIC NETWORK Geoprocessing Messages***\n"
        print arcpy.GetMessages(2)
    except Exception as ex:
        print "\n\n*** 2.2.1 TRACE GEOMETRIC NETWORK Exception Messages***\n"
        print ex.args[0]

    layers = arcpy.mapping.ListLayers(mxd)
    for layer in layers:
        if layer.isGroupLayer:
            if layer.name == "Network_from_Mains_Pipes":
                for subLayer in layer:
                    if subLayer.name == "Water_Main":
                        #Get list of isolated pipes
                        isolatedPipes = []
                        rows = arcpy.SearchCursor("Water_Main","","","OBJECTID_1")
                        for row in rows:
                            isolatedPipes.append(row.getValue("OBJECTID_1"))
                        del rows, row

                        try:
                            arcpy.FeatureClassToFeatureClass_conversion(subLayer, env.workspace, "Mains_Isolation")
                            # get gp messages for feature class to feature class tool
                            print "\n\n*** 2.2.2 FEATURE CLASS TO FEATURE CLASS Geoprocessing Messages***\n"
                            print arcpy.GetMessages()
                        except arcpy.ExecuteError:
                            print "\n\n*** 2.2.2 FEATURE CLASS TO FEATURE CLASS Geoprocessing Messages***\n"
                            print arcpy.GetMessages(2)
                        except Exception as ex:
                            print "\n\n*** 2.2.2 FEATURE CLASS TO FEATURE CLASS Exception Messages***\n"
                            print ex.args[0]

However, despite there being a selection on the network after a second trace, the same syntax doesn't export anything or create the list of affected pipes. It is like the resultant group layer from the second trace is invisible to the script. It is there in the TOC and I'm able to export the results manually.

                try:
                    arcpy.TraceGeometricNetwork_management('C:\\Users\\Desktop\\Working\\Water\\Data\\Process.gdb\\Geometric_Model\\Geometric_Model_Net',"Affected_Trace_Results","Flags2","FIND_CONNECTED","Barriers")
                    # get gp messages for trace geometric network tool
                    print "\n\n*** 2.2.1 TRACE GEOMETRIC NETWORK Geoprocessing Messages***\n"
                    print arcpy.GetMessages()
                except arcpy.ExecuteError:
                    print "\n\n*** 2.2.1 TRACE GEOMETRIC NETWORK Geoprocessing Messages***\n"
                    print arcpy.GetMessages(2)
                except Exception as ex:
                    print "\n\n*** 2.2.1 TRACE GEOMETRIC NETWORK Exception Messages***\n"
                    print ex.args[0]

                #Get list of affected downstream pipes from trace results and create affected network fc
                for layer in layers:
                    print layer.name
                    if layer.isGroupLayer:
                        print "Group Layer", layer.name
                        if layer.name == "Affected_Trace_Results":
                            for subLayer in layer:
                                print "Sub Layer", subLayer.name
                                if subLayer.name == "Water_Main":
                                    #Get list of affected pipes
                                    affectedPipes = []
                                    rows = arcpy.SearchCursor("Water_Main","","","OBJECTID_1")
                                    for row in rows:
                                        affectedPipes.append(row.getValue("OBJECTID_1"))
                                    del rows, row
                                    print "Affected Pipes", affectedPipes

                                    try:
                                        arcpy.MakeFeatureLayer_management(subLayer,"Mains_Affected","","","")
                                        # get gp messages for feature class to feature class tool
                                        print "\n\n*** 2.2.2 FEATURE CLASS TO FEATURE CLASS Geoprocessing Messages***\n"
                                        print arcpy.GetMessages()
                                    except arcpy.ExecuteError:
                                        print "\n\n*** 2.2.2 FEATURE CLASS TO FEATURE CLASS Geoprocessing Messages***\n"
                                        print arcpy.GetMessages(2)
                                    except Exception as ex:
                                        print "\n\n*** 2.2.2 FEATURE CLASS TO FEATURE CLASS Exception Messages***\n"
                                        print ex.args[0]

Can anybody shed any light?

closed as off-topic by PolyGeo Aug 16 '15 at 1:30

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Please post a snippet of your code. – Kirk Kuykendall Aug 13 '15 at 21:40
  • I've added the code snippets from the 2 traces. First one works just fine. Second trace completes and returns the group layer, but I can't access the water_main element of this group to export the selection. – Damien Aug 14 '15 at 8:10
  • 1
    I think I've found the solution to my problem. Adding the following line: arcpy.mapping.Layer("Affected_Trace_Results") to my code appears to make the group layer accessible. Thanks – Damien Aug 15 '15 at 18:57