You can wrap a code block in code tags when you place it in the message window It makes it easier to read
import arcpy
#Set geoprocessing environment
arcpy.env.workspace = "H:\Dr. Hines\New File Geodatabase.gdb"
arcpy.env.overwriteOutput = True
#Create list of all blocks
fcList = arcpy.ListFeatureClasses("*blk00")
#Create loop
for fc in fcList:
blk = fcLis
arcpy.SelectLayerByLocation_management("Analysis Roads","HAVE_THEIR_CENTER_IN")
for fc in fcList:
rows = arcpy.InsertCursor(blk)
row = rows.newRow()
row.STFID = ()
fieldVal = row.getValue("STFID")
arcpy.CalculateField_management("Analysis Roads","STFID","fieldVal")
import arcpy
#Set geoprocessing environment
arcpy.env.workspace = "H:\Dr. Hines\New File Geodatabase.gdb"
arcpy.env.overwriteOutput = True
#Create list of all blocks
fcList = arcpy.ListFeatureClasses("*blk00")
#Create loop
for fc in fcList:
selected = arcpy.SelectLayerByLocation_management("Analysis Roads","HAVE_THEIR_CENTER_IN", fc)
highway = "Analysis Roads"
rows = arcpy.UpdateCursor(higway)
for row in rows:
if row is in selected:
row.STFID = fc.STFID #this is assuming your feature classes have a STFID field too, you can change this to the right field name.
rows.updateRow(row)
import arcpy
#Set geoprocessing environment
arcpy.env.workspace = r"H:\Dr. Hines\New File Geodatabase.gdb" # \ is an escape character in python strings and needs the raw flag or to be doubled to act as a character
arcpy.env.overwriteOutput = True
#Create list of all blocks
fcList = arcpy.ListFeatureClasses("*blk00")
#Create loop
for fc in fcList:
blk = fcLis # Looks like a misspelling. Shouldn't this be fcList
arcpy.SelectLayerByLocation_management("Analysis Roads","HAVE_THEIR_CENTER_IN")
for fc in fcList: # this is bad. Never loop the same object within a loop of itself. Create a new list object to loop if you need an embedded loop.
rows = arcpy.InsertCursor(blk)
row = rows.newRow()
row.STFID = ()
fieldVal = row.getValue("STFID")
arcpy.CalculateField_management("Analysis Roads","STFID","fieldVal")
>>> import arcpy
>>> #Set geoprocessing environment
>>> arcpy.env.workspace = r"I:\Dr. Hines\New File Geodatabase.gdb"
>>> arcpy.env.overwriteOutput = True
>>> #Create list of all blocks
>>> fcList = arcpy.ListFeatureClasses("*blk00")
>>> #Create loop
>>> for fc in fcList:
... X = arcpy.SelectLayerByLocation_management("Analysis Roads","HAVE_THEIR_CENTER_IN", fc)
... highway = "Analysis Roads"
... rows = arcpy.UpdateCursor(highway)
... for row in rows:
... if row is in X:
... row.STFID = fc.STFID
... rows.updateRow(row)
... del row
... del rows
for fc in fcList:
X = arcpy.SelectLayerByLocation_management("Analysis Roads","HAVE_THEIR_CENTER_IN", fc)
highway = X #I think you want highway to = X which is the selection of analysis roads from the previous #operation?
rows = arcpy.UpdateCursor(highway)
for row in rows:
if row is in X:#I dont think this is correct if statement... should be something like if X==ROW
row.STFID = fc.STFID
rows.updateRow(row)
del row #these del row, del rows should be tabbed outside of the loop, not inside
del rows
import arcpy
#Set geoprocessing environment
arcpy.env.workspace = r"I:\Dr. Hines\New File Geodatabase.gdb"
arcpy.env.overwriteOutput = True
#Create list of all blocks
fcList = arcpy.ListFeatureClasses("*blk00")
highway = "Analysis Roads"
#Create loop
for fc in fcList:
arcpy.SelectLayerByLocation_management(highway,"HAVE_THEIR_CENTER_IN", fc)
rows = arcpy.UpdateCursor(highway)
for row in rows:
row.STFID = fc.STFID
rows.updateRow(row)
del row
del rows