I'm having issues with writing some values from 2 tables deep (nested). I'm trying to get the X,Y values of a line that is nested twice from the parent. If that makes sense.
So I have a point. That point looks in another dataset then once it finds that it looks into another dataset for the values. I'm trying to get those values from the 3 table be written in the first table.
Here is my code. I almost got it, but I get an undefined variable error on line 58.
global lat global long #Search each record in Queue table with arcpy.da.UpdateCursor (tbl, inputtable_fields) as Scur2: for row1 in Scur2: Sub1 = row1 Sub2 = row1 FIPS_var = row1 state_var = row1 queid = row1 arcpy.AddMessage(queid + ",") with arcpy.da.SearchCursor(tline_lyr, tline_lyr_fields) as Scur: #arcpy.AddMessage(Sub1 + "," + Sub2+ ",") for row in Scur: if (row == Sub1 and row == Sub2) or (row == Sub2 and row == Sub1): Rec_ID_var = str(row) #arcpy.AddMessage ("the power line is "+ Rec_ID_var) #Select Power line selectline_var = arcpy.SelectLayerByAttribute_management(tline_lyr, 'NEW_SELECTION', "Rec_ID = " + Rec_ID_var) #Create in memory feature to get centroid of slected line. arcpy.CopyFeatures_management(selectline_var, r'in_memory\SelectedLine') #Select County by Attribute #arcpy.SelectLayerByLocation_management(county_lyr, 'INTERSECT', r'in_memory\SelectedLine', '#', 'NEW_SELECTION', 'NOT_INVERT') #Select County to use as a clip arcpy.SelectLayerByAttribute_management(county_lyr, 'NEW_SELECTION', "FIPS = '"+FIPS_var+"'" ) #Clip line with the County arcpy.Clip_analysis(r'in_memory\SelectedLine', county_lyr, r'in_memory\SelectedLineClipped', '#') #Create the mid point arcpy.FeatureToPoint_management(r'in_memory\SelectedLineClipped', r'in_memory\LineMidPT', 'INSIDE') #Calculates Lat + Long arcpy.AddGeometryAttributes_management(r'in_memory\LineMidPT', 'POINT_X_Y_Z_M', '#', '#', WGS_1984_CS) #Print out lat long with arcpy.da.SearchCursor(r'in_memory\LineMidPT', ["POINT_X","POINT_Y"]) as Scur: for row in Scur: arcpy.AddMessage(str(row)) arcpy.AddMessage(str(row)) long = row lat = row arcpy.management.SelectLayerByAttribute(tline_lyr, 'CLEAR_SELECTION') arcpy.management.SelectLayerByAttribute(county_lyr, 'CLEAR_SELECTION') row1 = long row1 = lat cursor.updateRow(row)
I've also tried this with a try statement on line 58. But then it doesn't write anything.
Try changing lines 58 and 59 to "row1" instead of "row". Even if that resolves your error on line 58, you will get one on line 60 because there is not cursor named "cursor".
There are other issues I see with your code, but I have to jump on a call shortly. I will try to follow-up later.