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.
Thanks
<SPAN class="keyword token">global</SPAN> lat
<SPAN class="keyword token">global</SPAN> long
<SPAN class="comment token">#Search each record in Queue table </SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor <SPAN class="punctuation token">(</SPAN>tbl<SPAN class="punctuation token">,</SPAN> inputtable_fields<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> Scur2<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> row1 <SPAN class="keyword token">in</SPAN> Scur2<SPAN class="punctuation token">:</SPAN>
Sub1 <SPAN class="operator token">=</SPAN> row1<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
Sub2 <SPAN class="operator token">=</SPAN> row1<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN>
FIPS_var <SPAN class="operator token">=</SPAN> row1<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN>
state_var <SPAN class="operator token">=</SPAN> row1<SPAN class="punctuation token">[</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">]</SPAN>
queid <SPAN class="operator token">=</SPAN> row1<SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN>queid <SPAN class="operator token">+</SPAN> <SPAN class="string token">","</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>tline_lyr<SPAN class="punctuation token">,</SPAN> tline_lyr_fields<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> Scur<SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token">#arcpy.AddMessage(Sub1 + "," + Sub2+ ",")</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> Scur<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">==</SPAN> Sub1 <SPAN class="operator token">and</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">==</SPAN> Sub2<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">or</SPAN> <SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">==</SPAN> Sub2 <SPAN class="operator token">and</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">==</SPAN> Sub1<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
Rec_ID_var <SPAN class="operator token">=</SPAN> str<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#arcpy.AddMessage ("the power line is "+ Rec_ID_var) </SPAN>
<SPAN class="comment token">#Select Power line</SPAN>
selectline_var <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN>tline_lyr<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'NEW_SELECTION'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Rec_ID = "</SPAN> <SPAN class="operator token">+</SPAN> Rec_ID_var<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Create in memory feature to get centroid of slected line. </SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CopyFeatures_management<SPAN class="punctuation token">(</SPAN>selectline_var<SPAN class="punctuation token">,</SPAN> r<SPAN class="string token">'in_memory\SelectedLine'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Select County by Attribute </SPAN>
<SPAN class="comment token">#arcpy.SelectLayerByLocation_management(county_lyr, 'INTERSECT', r'in_memory\SelectedLine', '#', 'NEW_SELECTION', 'NOT_INVERT')</SPAN>
<SPAN class="comment token">#Select County to use as a clip </SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute_management<SPAN class="punctuation token">(</SPAN>county_lyr<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'NEW_SELECTION'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"FIPS = '"</SPAN><SPAN class="operator token">+</SPAN>FIPS_var<SPAN class="operator token">+</SPAN><SPAN class="string token">"'"</SPAN> <SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Clip line with the County</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Clip_analysis<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">'in_memory\SelectedLine'</SPAN><SPAN class="punctuation token">,</SPAN> county_lyr<SPAN class="punctuation token">,</SPAN> r<SPAN class="string token">'in_memory\SelectedLineClipped'</SPAN><SPAN class="punctuation token">,</SPAN> '<SPAN class="comment token">#')</SPAN>
<SPAN class="comment token">#Create the mid point</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>FeatureToPoint_management<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">'in_memory\SelectedLineClipped'</SPAN><SPAN class="punctuation token">,</SPAN> r<SPAN class="string token">'in_memory\LineMidPT'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'INSIDE'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Calculates Lat + Long</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddGeometryAttributes_management<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">'in_memory\LineMidPT'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'POINT_X_Y_Z_M'</SPAN><SPAN class="punctuation token">,</SPAN> '<SPAN class="comment token">#', '#', WGS_1984_CS)</SPAN>
<SPAN class="comment token">#Print out lat long </SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">'in_memory\LineMidPT'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"POINT_X"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"POINT_Y"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> Scur<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> Scur<SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN>str<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN>str<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
long <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
lat <SPAN class="operator token">=</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>management<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute<SPAN class="punctuation token">(</SPAN>tline_lyr<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'CLEAR_SELECTION'</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>management<SPAN class="punctuation token">.</SPAN>SelectLayerByAttribute<SPAN class="punctuation token">(</SPAN>county_lyr<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'CLEAR_SELECTION'</SPAN><SPAN class="punctuation token">)</SPAN>
row1<SPAN class="punctuation token">[</SPAN><SPAN class="number token">5</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> long
row1<SPAN class="punctuation token">[</SPAN><SPAN class="number token">6</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> lat
cursor<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>I've also tried this with a try statement on line 58. But then it doesn't write anything.
Thanks!