<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Need script to select each feature, one at a time in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/need-script-to-select-each-feature-one-at-a-time/m-p/496777#M39020</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;investigate either nested lists of all the field values you need from each record:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;allrecordsList = [[field1, field2, field3], [field1, field2, field3], [field1, field2, field3], ...]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;or, try a dictionary for a similar thing.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 02 Nov 2012 18:57:39 GMT</pubDate>
    <dc:creator>markdenil</dc:creator>
    <dc:date>2012-11-02T18:57:39Z</dc:date>
    <item>
      <title>Need script to select each feature, one at a time</title>
      <link>https://community.esri.com/t5/python-questions/need-script-to-select-each-feature-one-at-a-time/m-p/496774#M39017</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello all-&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm having a tough time getting started on what should be a relatively simple script. I have a feature class consisting of sinks in a geometric network. I need my script to initially select the first record, perform some functions, finish those functions, then move to the next record, and repeat until the end. I've set up a search cursor to cycle through the records, but my problem is making a feature layer from the "current" record in the search cursor. Any input on how I could do this? Thanks, John&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2012 11:36:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-script-to-select-each-feature-one-at-a-time/m-p/496774#M39017</guid>
      <dc:creator>johnodonnell</dc:creator>
      <dc:date>2012-11-02T11:36:10Z</dc:date>
    </item>
    <item>
      <title>Re: Need script to select each feature, one at a time</title>
      <link>https://community.esri.com/t5/python-questions/need-script-to-select-each-feature-one-at-a-time/m-p/496775#M39018</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You want to use your cursor to build a list of the individual features in the fc&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Then use the list to cycle through the fc, picking each in turn.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#&amp;nbsp; make a list of the feature IDs
theSource = r"C:\some.gdb\FeatureClass"
cur = arcpy.SearchCursor(theSource)
theIdList = []
for row in cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp; theID = row.OBJECTID
&amp;nbsp;&amp;nbsp;&amp;nbsp; if theID not in theIdList:
 theIdList.append(theID)
del cur

#&amp;nbsp; count the entries in the list
idCount = len(idList)

for each in range(idCount):
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "%s of %s" % (each + 1, idCount)
&amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp;&amp;nbsp; build a feature where clause
&amp;nbsp;&amp;nbsp;&amp;nbsp; segWhere = '"OBJECTID" = %s' % idList[each]

&amp;nbsp;&amp;nbsp;&amp;nbsp; #&amp;nbsp;&amp;nbsp; make a layer of each feature in fc
&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists("MyTempLayer"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(("MyTempLayer")

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(theSource,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "MyTempLayer",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; segWhere)
&amp;nbsp;&amp;nbsp;&amp;nbsp; ###&amp;nbsp; Do stuff to that feature here....&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:50:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-script-to-select-each-feature-one-at-a-time/m-p/496775#M39018</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2021-12-11T21:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: Need script to select each feature, one at a time</title>
      <link>https://community.esri.com/t5/python-questions/need-script-to-select-each-feature-one-at-a-time/m-p/496776#M39019</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the reply! I think this will work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;After writing more script, I'm coming across another issue. I'm basically performing a TRACE_UPSTREAM on each feature in the feature class. That will produce a selection set of upstream structures and conveyances. I want to take the unique FacilityID from the selected sink and update the selected upstream structures with that value. I have set up an update cursor to update the records, but I'm getting an error when trying to get the value from the selected sink. I guess once the feature is in a list I can no longer use the getValue command. So should I store this value in the list as well?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for any input.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2012 14:45:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-script-to-select-each-feature-one-at-a-time/m-p/496776#M39019</guid>
      <dc:creator>johnodonnell</dc:creator>
      <dc:date>2012-11-02T14:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: Need script to select each feature, one at a time</title>
      <link>https://community.esri.com/t5/python-questions/need-script-to-select-each-feature-one-at-a-time/m-p/496777#M39020</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;investigate either nested lists of all the field values you need from each record:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;allrecordsList = [[field1, field2, field3], [field1, field2, field3], [field1, field2, field3], ...]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;or, try a dictionary for a similar thing.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2012 18:57:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-script-to-select-each-feature-one-at-a-time/m-p/496777#M39020</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2012-11-02T18:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: Need script to select each feature, one at a time</title>
      <link>https://community.esri.com/t5/python-questions/need-script-to-select-each-feature-one-at-a-time/m-p/496778#M39021</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've built a lot upon the above suggestions and currently have a script that will:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Add all sink features to a list.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Use the list to cycle through the features and select them one at a time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Create feature layer from this selection.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4. Use the feature layer as a sink to trace the geometric network.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;5. Update the selected (traced) features in a networked feature class with the FacilityID of the first selected sink.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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, John&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import 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:
&amp;nbsp;&amp;nbsp;&amp;nbsp; featureID = row.OBJECTID
&amp;nbsp;&amp;nbsp;&amp;nbsp; if featureID not in sinkList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sinkList.append(featureID)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next()
del rows

print sinkList

sinkCount = len(sinkList)

for each in range(sinkCount):
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "%s of %s" % (each +1, sinkCount)
&amp;nbsp;&amp;nbsp;&amp;nbsp; sinkWhere = '"OBJECTID" = %s' % sinkList[each]

&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists("TempSinkLayer"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management("TempSinkLayer")


&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(sinkFeatures, "TempSinkLayer", sinkWhere)

&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor = arcpy.SearchCursor("TempSinkLayer")
&amp;nbsp;&amp;nbsp;&amp;nbsp; sink = cursor.next()
&amp;nbsp;&amp;nbsp;&amp;nbsp; while sink:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; facID = sink.getValue("FACILITYID")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print facID
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sink = cursor.next()
&amp;nbsp;&amp;nbsp;&amp;nbsp; del sink
&amp;nbsp;&amp;nbsp;&amp;nbsp; del cursor


&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outGroupLayer = "Trace" + facID
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetFlowDirection_management(geometricNetwork, "WITH_DIGITIZED_DIRECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.TraceGeometricNetwork_management(geometricNetwork, outGroupLayer, "TempSinkLayer", "TRACE_UPSTREAM", "", "", "", "", "", "", "" ,"", "", "", "", "", "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Can't trace"

&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dCatchLayer = facID + "dCatch"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectData_management(outGroupLayer, "DCatchBasin_Master")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management("DCatchBasin_Master", dCatchLayer)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = int(arcpy.GetCount_management(dCatchLayer).getOutput(0))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print result
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "can't make feature layer or access selection"


&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dCatchs = arcpy.UpdateCursor(dCatchLayer)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dCatch = dCatchs.next()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldID = "DnComboFacID"

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while dCatch:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dCatch.setValue(fieldID, facID)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dCatchs.updateRow(dCatch)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dCatch = dCatchs.next()

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del dCatch
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del dCatchs

&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "can't update rows"


&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(dCatchLayer)
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "can't delete the feature layer"

&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("DCatchBasin_Master", "CLEAR_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for df in arcpy.mapping.ListDataFrames(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd, "", df):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == "Trace" + facID:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.RemoveLayer(df, lyr)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass

&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "can't delete the group layer"





&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:50:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-script-to-select-each-feature-one-at-a-time/m-p/496778#M39021</guid>
      <dc:creator>johnodonnell</dc:creator>
      <dc:date>2021-12-11T21:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: Need script to select each feature, one at a time</title>
      <link>https://community.esri.com/t5/python-questions/need-script-to-select-each-feature-one-at-a-time/m-p/496779#M39022</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I got it working! For anyone interested, the following script will take a point feature class representing sinks in a geometric network, select each one at a time, trace upstream from each, and update a field in an upstream feature class with a unique ID of the sink it traces to. Cheers!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import 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\\SManhole_Master"
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:
&amp;nbsp;&amp;nbsp;&amp;nbsp; featureID = row.OBJECTID
&amp;nbsp;&amp;nbsp;&amp;nbsp; if featureID not in sinkList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sinkList.append(featureID)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next()
del rows

print sinkList

sinkCount = len(sinkList)

for each in range(sinkCount):
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "%s of %s" % (each +1, sinkCount)
&amp;nbsp;&amp;nbsp;&amp;nbsp; sinkWhere = '"OBJECTID" = %s' % sinkList[each]

&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists("TempSinkLayer"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management("TempSinkLayer")


&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(sinkFeatures, "TempSinkLayer", sinkWhere)

&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor = arcpy.SearchCursor("TempSinkLayer")
&amp;nbsp;&amp;nbsp;&amp;nbsp; sink = cursor.next()
&amp;nbsp;&amp;nbsp;&amp;nbsp; while sink:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; facID = sink.getValue("FACILITYID")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print facID
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sink = cursor.next()
&amp;nbsp;&amp;nbsp;&amp;nbsp; del sink
&amp;nbsp;&amp;nbsp;&amp;nbsp; del cursor


&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outGroupLayer = str("Trace" + facID)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetFlowDirection_management(geometricNetwork, "WITH_DIGITIZED_DIRECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.TraceGeometricNetwork_management(geometricNetwork, outGroupLayer, "TempSinkLayer", "TRACE_UPSTREAM", "", "", "", "", "", "", "" ,"", "", "", "", "", "", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Can't trace"

&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dCatchLayer = str(facID + "dCatch")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectData_management(outGroupLayer, "DCatchBasin_Master")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management("DCatchBasin_Master", dCatchLayer)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = int(arcpy.GetCount_management(dCatchLayer).getOutput(0))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print result

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dCatchs = arcpy.UpdateCursor(dCatchLayer)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dCatch = dCatchs.next()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldID = "DnComboFacID"

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while dCatch:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dCatch.setValue(fieldID, facID)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dCatchs.updateRow(dCatch)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dCatch = dCatchs.next()

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del dCatch
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del dCatchs

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(dCatchLayer)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management("DCatchBasin_Master")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management("DCatchBasin_Master", "CLEAR_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##for df in arcpy.mapping.ListDataFrames(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##for lyr in arcpy.mapping.ListLayers(mxd, "", df):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##if lyr.name == "Trace" + facID:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##arcpy.mapping.RemoveLayer(df, lyr)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##pass

&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "not working"





&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PS- the code works within PyScripter, but for some reason gets wonky results when run within ArcMap.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:50:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-script-to-select-each-feature-one-at-a-time/m-p/496779#M39022</guid>
      <dc:creator>johnodonnell</dc:creator>
      <dc:date>2021-12-11T21:50:22Z</dc:date>
    </item>
  </channel>
</rss>

