I've built a lot upon the above suggestions and currently have a script that will:1. Add all sink features to a list.2. Use the list to cycle through the features and select them one at a time.3. Create feature layer from this selection.4. Use the feature layer as a sink to trace the geometric network.5. Update the selected (traced) features in a networked feature class with the FacilityID of the first selected sink.I need for the script to eliminate the selection and start fresh with the next feature in line, trace from there, and update all the upstream selected features. However, as of now it will not produce the intended results. What's confusing is I get different messages/results every time I run it. Could anyone please take a look and see if I'm missing something obvious? Thanks, Johnimport arcpy
arcpy.env.overwriteOutput=True
arcpy.env.workspace = "D:\FacID_Python\SO_CSS_Master_9x_GDB.gdb"
sinkFeatures = "D:\\FacID_Python\\SO_CSS_Master_9x_GDB.gdb\\SO_CSS_Master\\Export_Output"
dCatchBasin = "D:\\FacID_Python\\SO_CSS_Master_9x_GDB.gdb\\SO_CSS_Master\\DCatchBasin_Master"
geometricNetwork = "D:\\FacID_Python\\SO_CSS_Master_9x_GDB.gdb\\SO_CSS_Master\\SO_CSS_Master_Net"
mxd = arcpy.mapping.MapDocument("D:\FacID_Python\Working.mxd")
sinkList = []
rows = arcpy.SearchCursor(sinkFeatures)
row = rows.next()
while row:
featureID = row.OBJECTID
if featureID not in sinkList:
sinkList.append(featureID)
row = rows.next()
del rows
print sinkList
sinkCount = len(sinkList)
for each in range(sinkCount):
print "%s of %s" % (each +1, sinkCount)
sinkWhere = '"OBJECTID" = %s' % sinkList[each]
if arcpy.Exists("TempSinkLayer"):
arcpy.Delete_management("TempSinkLayer")
arcpy.MakeFeatureLayer_management(sinkFeatures, "TempSinkLayer", sinkWhere)
cursor = arcpy.SearchCursor("TempSinkLayer")
sink = cursor.next()
while sink:
facID = sink.getValue("FACILITYID")
print facID
sink = cursor.next()
del sink
del cursor
try:
outGroupLayer = "Trace" + facID
arcpy.SetFlowDirection_management(geometricNetwork, "WITH_DIGITIZED_DIRECTION")
arcpy.TraceGeometricNetwork_management(geometricNetwork, outGroupLayer, "TempSinkLayer", "TRACE_UPSTREAM", "", "", "", "", "", "", "" ,"", "", "", "", "", "", "")
except:
print "Can't trace"
try:
dCatchLayer = facID + "dCatch"
arcpy.SelectData_management(outGroupLayer, "DCatchBasin_Master")
arcpy.MakeFeatureLayer_management("DCatchBasin_Master", dCatchLayer)
result = int(arcpy.GetCount_management(dCatchLayer).getOutput(0))
print result
except:
print "can't make feature layer or access selection"
try:
dCatchs = arcpy.UpdateCursor(dCatchLayer)
dCatch = dCatchs.next()
fieldID = "DnComboFacID"
while dCatch:
dCatch.setValue(fieldID, facID)
dCatchs.updateRow(dCatch)
dCatch = dCatchs.next()
del dCatch
del dCatchs
except:
print "can't update rows"
try:
arcpy.Delete_management(dCatchLayer)
except:
print "can't delete the feature layer"
try:
arcpy.SelectLayerByAttribute_management("DCatchBasin_Master", "CLEAR_SELECTION")
for df in arcpy.mapping.ListDataFrames(mxd):
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
if lyr.name == "Trace" + facID:
arcpy.mapping.RemoveLayer(df, lyr)
else:
pass
except:
print "can't delete the group layer"