myaoi = '69257'
fc = "AOI"
for eachaoi in aoilst: #List of all the AOI's that surround my AOI = 69257
sbaAOI = "AOI = '" + eachaoi + "'"
print ("Current AOI selected = " + eachaoi)
print sbaAOI
arcpy.SelectLayerByAttribute_management("AOI","NEW_SELECTION",sbaAOI)
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
arcpy.SelectLayerByLocation_management("PLines","SHARE_A_LINE_SEGMENT_WITH","AOI")
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
with arcpy.da.SearchCursor(fc, "AOI") as cursor:
for row in cursor:
mysharedaoi = ("'" + row[0] + "'")
print mysharedaoi
if int(row[0]) < int(myaoi):
print ("SharedAOI needs to be calc'd with myaoi")
#arcpy.CalculateField_management("PLines", "AOI",'99999')
arcpy.CalculateField_management("PLines", "AOI", "mysharedaoi")
arcpy.CalculateField_management("PLines", "SharedAOI","myaoi")
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
print ("lines calculated")
elif int(row[0]) > int(myaoi):
print ("AOI needs to be calc'd with myaoi")
arcpy.CalculateField_management("PLines", "AOI", "myaoi")
#arcpy.CalculateField_management("PLines", "SharedAOI",'99999')
arcpy.CalculateField_management("PLines", "SharedAOI","mysharedaoi")
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
print ("lines calculated")#Hardcoded AOI's & SharedAOI's for CalculateField works as expected.
#This sequence uses selected aoi to grab all parcel lines sharing segment, then selects adjacent AOI's
#sharing segment with parcel lines.
arcpy.SelectLayerByLocation_management("PLines","SHARE_A_LINE_SEGMENT_WITH","AOI")
arcpy.SelectLayerByLocation_management("AOI","SHARE_A_LINE_SEGMENT_WITH","PLines")
aoilst = []
with arcpy.da.SearchCursor("AOI","AOI") as cursor:
for row in cursor:
print row[0]
aoilst.append(row[0])
del cursor, row
myaoi = '69257'
fc = "AOI"
for eachaoi in aoilst:
mysharedaoi = "'" + eachaoi + "'"
print "mysharedaoi = " + mysharedaoi
sbaAOI = "AOI = '" + eachaoi + "'"
print ("Current AOI selected = " + eachaoi)
print sbaAOI
arcpy.SelectLayerByAttribute_management("AOI","NEW_SELECTION",sbaAOI)
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
arcpy.SelectLayerByLocation_management("PLines","SHARE_A_LINE_SEGMENT_WITH","AOI")
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
if int(eachaoi) < int(myaoi):
print ("SharedAOI needs to be calc'd with myaoi")
#arcpy.CalculateField_management("PLines", "SharedAOI",myaoi) Variables replaced with hardcoded values
#arcpy.CalculateField_management("PLines", "AOI", mysharedaoi) Variables replaced with hardcoded values
arcpy.CalculateField_management("PLines", "SharedAOI",'69257')
arcpy.CalculateField_management("PLines", "AOI", '99999')
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
print ("lines calculated")
elif int(eachaoi) > int(myaoi):
print ("AOI needs to be calc'd with myaoi")
#arcpy.CalculateField_management("PLines", "AOI", myaoi)
#arcpy.CalculateField_management("PLines", "SharedAOI", mysharedaoi)
arcpy.CalculateField_management("PLines", "SharedAOI",'99999')
arcpy.CalculateField_management("PLines", "AOI", '69257')
arcpy.RefreshTOC()
arcpy.RefreshActiveView()
print ("lines calculated")Kept working on the issue to try to simplify code. Saw no need to use cursor at all. However, the CalculateField still presents issues.
If I hardcode the values for AOI and SharedAOI within the PLines attribute table, the entire process works perfectly.
However, if I attempt to use a variable, ie: myaoi = '69257', mysharedaoi = 'value_from_current_selected_AOI', still resulting in the
values being shown as 'xxxxx', exactly like hardcoded values, then I will get an error everytime. It seems that each combination of quotes, double quotes, etc. will produce a different error. Sometimes an empty selection set, and sometimes can't acquire data lock.#Hardcoded AOI's & SharedAOI's for CalculateField works as expected. #This sequence uses selected aoi to grab all parcel lines sharing segment, then selects adjacent AOI's #sharing segment with parcel lines. arcpy.SelectLayerByLocation_management("PLines","SHARE_A_LINE_SEGMENT_WITH","AOI") arcpy.SelectLayerByLocation_management("AOI","SHARE_A_LINE_SEGMENT_WITH","PLines") aoilst = [] with arcpy.da.SearchCursor("AOI","AOI") as cursor: for row in cursor: print row[0] aoilst.append(row[0]) del cursor, row myaoi = '69257' fc = "AOI" for eachaoi in aoilst: mysharedaoi = "'" + eachaoi + "'" print "mysharedaoi = " + mysharedaoi sbaAOI = "AOI = '" + eachaoi + "'" print ("Current AOI selected = " + eachaoi) print sbaAOI arcpy.SelectLayerByAttribute_management("AOI","NEW_SELECTION",sbaAOI) arcpy.RefreshActiveView() arcpy.RefreshTOC() arcpy.SelectLayerByLocation_management("PLines","SHARE_A_LINE_SEGMENT_WITH","AOI") arcpy.RefreshActiveView() arcpy.RefreshTOC() if int(eachaoi) < int(myaoi): print ("SharedAOI needs to be calc'd with myaoi") #arcpy.CalculateField_management("PLines", "SharedAOI",myaoi) Variables replaced with hardcoded values #arcpy.CalculateField_management("PLines", "AOI", mysharedaoi) Variables replaced with hardcoded values arcpy.CalculateField_management("PLines", "SharedAOI",'69257') arcpy.CalculateField_management("PLines", "AOI", '99999') arcpy.RefreshTOC() arcpy.RefreshActiveView() print ("lines calculated") elif int(eachaoi) > int(myaoi): print ("AOI needs to be calc'd with myaoi") #arcpy.CalculateField_management("PLines", "AOI", myaoi) #arcpy.CalculateField_management("PLines", "SharedAOI", mysharedaoi) arcpy.CalculateField_management("PLines", "SharedAOI",'99999') arcpy.CalculateField_management("PLines", "AOI", '69257') arcpy.RefreshTOC() arcpy.RefreshActiveView() print ("lines calculated")
Once again, thank you for any assistance with this problem.
Thank you for your reply. After continuing to work on the problem, I discovered the same problem myself. So I changed all my
CalculateField lines adding the critical "PYTHON_9.3" to the end of my line. After a lot of testing, I can confirm that this fix was
exactly what was needed and it works perfectly.