<?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: Select features from layers and send to output tables... in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/select-features-from-layers-and-send-to-output/m-p/31116#M2459</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Clearly, you are expecting to do more than just extract the data to tables. You accomplish that with CopyRows.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It looks like you are also wanting a text output: a file or report of some kind.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you really want the table? or just the report? or both?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am guessing that the report will appear on the map, and that is what the ~text.text elements are.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why do you define the cursors inside the table extraction loop?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You know what your target tables will be named (or the variables that will hold the names),&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and you seem to be doing the same thing to each output table&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why use a list of the extracted tables, and loop through them, reusing the cursor &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(and doing something with the cursor output before looping)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for tbl in [tbl1, tbl2]:
&amp;nbsp;&amp;nbsp;&amp;nbsp; cur&amp;nbsp; = arcpy.SearchCursor(tbl,"","","Valve_ID; ... ect...&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Further, you could write your three output coulmn value vars as elements in a list,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and give the lists names in nested lists in a modification of the table list as shown above.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
t1OUT = []
t2OUT = []
for tbl in [[tbl1, t1OUT], [tbl2, t2OUT]]:

&amp;nbsp;&amp;nbsp;&amp;nbsp; cur&amp;nbsp; = arcpy.SearchCursor(tbl[0],"","","Valve_ID; ... ect...&amp;nbsp; # &amp;lt;- note that tbl is now a list
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp; other stuff
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Col1Value += str(row.Valve_ID) + "\n"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # ... and so on...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tbl[1].append([Col1Value, Col2Value, Col3Value])
&amp;nbsp;&amp;nbsp;&amp;nbsp; del cur
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Then go on to write your text element text from the t1OUT and t2OUT tables, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;concatenating each list content into one line string.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is obviously quite rough, but may be simpler&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 21:15:00 GMT</pubDate>
    <dc:creator>markdenil</dc:creator>
    <dc:date>2021-12-10T21:15:00Z</dc:date>
    <item>
      <title>Select features from layers and send to output tables...</title>
      <link>https://community.esri.com/t5/python-questions/select-features-from-layers-and-send-to-output/m-p/31115#M2458</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm sure there is an easier way to do this so any help would be appreciated:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a shapefile with all valves (hydrant valves and main valves) included in it.&amp;nbsp; I want to select all of the main valves in the currentview extent and output them to a table called "Main Valves" and select the hydrant valves in the current extent and output them to a table called "Hydrant Valves".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd, "", df):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == "Main Valves"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extentPolygon = arcpy.Polygon(arcpy.Array([df.extent.lowerLeft,df.extent.lowerRight, df.extent.upperRight, df.extent.upperLeft]),df.spatialReference)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", extentPolygon, "", "NEW_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyRows_management("Main valves", tbl1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mainvalves_outputrows = arcpy.SearchCursor(tbl1,"","","Valve_ID; vDiameter; LOCATION_DATA","Valve_ID")
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif lyr.name == "Hydrant Valves"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extentPolygon = arcpy.Polygon(arcpy.Array([df.extent.lowerLeft,df.extent.lowerRight, df.extent.upperRight, df.extent.upperLeft]),df.spatialReference)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", extentPolygon, "", "NEW_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyRows_management("Hydrant valves", tbl2)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; hydrantvalves_outputrows = arcpy.SearchCursor(tbl2,"","","Valve_ID; vDiameter; LOCATION_DATA","Valve_ID")
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp; Clear all table text values
&amp;nbsp; tab1Col1Txt.text = " "; tab1Col2Txt.text = " "; tab1Col3Txt.text = " "
&amp;nbsp; tab1Col1Value = ""
&amp;nbsp; tab1Col2Value = ""
&amp;nbsp; tab1Col3Value = ""
&amp;nbsp; tab2Col1Txt.text = " "; tab2Col2Txt.text = " "; tab2Col3Txt.text = " "
&amp;nbsp; tab2Col1Value = ""
&amp;nbsp; tab2Col2Value = ""
&amp;nbsp; tab2Col3Value = ""
&amp;nbsp; 
&amp;nbsp; for row in mainvalves_outputrows: 
&amp;nbsp;&amp;nbsp;&amp;nbsp; tab1Col1Value += str(row.Valve_ID) + "\n"
&amp;nbsp;&amp;nbsp;&amp;nbsp; tab1Col2Value += str(row.vDiameter) + "\n"
&amp;nbsp;&amp;nbsp;&amp;nbsp; tab1Col3Value += str(row.LOCATION_DATA) + "\n"

&amp;nbsp; tab1Col1Txt.text = tab1Col1Value
&amp;nbsp; tab1Col2Txt.text = tab1Col2Value
&amp;nbsp; tab1Col3Txt.text = tab1Col3Value

&amp;nbsp; for row in hydrantvalves_outputrows: 
&amp;nbsp;&amp;nbsp;&amp;nbsp; tab2Col1Value += str(row.Valve_ID) + "\n"
&amp;nbsp;&amp;nbsp;&amp;nbsp; tab2Col2Value += str(row.vDiameter) + "\n"
&amp;nbsp;&amp;nbsp;&amp;nbsp; tab2Col3Value += str(row.LOCATION_DATA) + "\n"

&amp;nbsp; tab2Col1Txt.text = tab2Col1Value
&amp;nbsp; tab2Col2Txt.text = tab2Col2Value
&amp;nbsp; tab2Col3Txt.text = tab2Col3Value&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Dec 2012 21:34:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-features-from-layers-and-send-to-output/m-p/31115#M2458</guid>
      <dc:creator>JonathanHodel</dc:creator>
      <dc:date>2012-12-04T21:34:45Z</dc:date>
    </item>
    <item>
      <title>Re: Select features from layers and send to output tables...</title>
      <link>https://community.esri.com/t5/python-questions/select-features-from-layers-and-send-to-output/m-p/31116#M2459</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Clearly, you are expecting to do more than just extract the data to tables. You accomplish that with CopyRows.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It looks like you are also wanting a text output: a file or report of some kind.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you really want the table? or just the report? or both?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am guessing that the report will appear on the map, and that is what the ~text.text elements are.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why do you define the cursors inside the table extraction loop?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You know what your target tables will be named (or the variables that will hold the names),&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and you seem to be doing the same thing to each output table&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why use a list of the extracted tables, and loop through them, reusing the cursor &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;(and doing something with the cursor output before looping)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for tbl in [tbl1, tbl2]:
&amp;nbsp;&amp;nbsp;&amp;nbsp; cur&amp;nbsp; = arcpy.SearchCursor(tbl,"","","Valve_ID; ... ect...&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Further, you could write your three output coulmn value vars as elements in a list,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and give the lists names in nested lists in a modification of the table list as shown above.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
t1OUT = []
t2OUT = []
for tbl in [[tbl1, t1OUT], [tbl2, t2OUT]]:

&amp;nbsp;&amp;nbsp;&amp;nbsp; cur&amp;nbsp; = arcpy.SearchCursor(tbl[0],"","","Valve_ID; ... ect...&amp;nbsp; # &amp;lt;- note that tbl is now a list
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cur:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ##&amp;nbsp; other stuff
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Col1Value += str(row.Valve_ID) + "\n"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # ... and so on...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tbl[1].append([Col1Value, Col2Value, Col3Value])
&amp;nbsp;&amp;nbsp;&amp;nbsp; del cur
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Then go on to write your text element text from the t1OUT and t2OUT tables, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;concatenating each list content into one line string.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is obviously quite rough, but may be simpler&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:15:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/select-features-from-layers-and-send-to-output/m-p/31116#M2459</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2021-12-10T21:15:00Z</dc:date>
    </item>
  </channel>
</rss>

