<?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: Searching for relate cursor example in Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/searching-for-relate-cursor-example-in-python/m-p/94402#M7370</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Holly, this should get you started... The #'s are Python comments...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What you do at the end (writing to new table) really depends on what you calculate and where it ends up. In this little example I created a table, but you could also copy rows or something like that.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, I haven't tested it out (there could be typo's, etc.).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;in_tablePath = arcpy.GetParameterAsText(0) # full path to input table (includes name)
out_tablePath = arcpy.GetParameterAsText(1) # path to output table
out_tableName = arcpy.GetParameterAsText(2) # name of output table
featureClass_dataset = arcpy.GetParameterAsText(3) # path to the .gdb (or Folder if .shp) of the feature classes

if not arcpy.Exists(in_tablePath): # check in case table doesn't exist...
 arcpy.AddError('Table, ' + in_tablePath + ', does not exist...')
 
else: # table does exist, continue
 arcpy.AddMessage('Using table: ' + in_tablePath) # let the user know the table path
 
 arcpy.CreateTable_management(out_tablePath, out_tableName) # create the output table...
 
 arcpy.AddField_management(out_tablePath+'\\'+out_tableName, "outputData", "DOUBLE") # add a field to the new table
 arcpy.CalculateField_management(out_tablePath+'\\'+out_tableName, "outputData", 0, "PYTHON") # calculate its value as 0 for now... (optional)
 
 rowList = arcpy.SearchCursor(in_tablePath)
 for row in rowList: # for every row
&amp;nbsp; 
&amp;nbsp; parcelID = row.getValue("parcelid")
&amp;nbsp; 
&amp;nbsp; # i.e. if the feature classes are in C:\GIS\Data\parcels.gdb, and parcelID = 7
&amp;nbsp; #&amp;nbsp; will return the feature class C:\GIS\Data\parcels.gdb\7
&amp;nbsp; featureClass = featureClass_dataset + '\\' + str(parcelID) # make sure parcelID is changed to a string as well
&amp;nbsp; 
&amp;nbsp; if not arcpy.Exists(featureClass): # check in case feature class doesn't exist...
&amp;nbsp;&amp;nbsp; arcpy.AddError('Feature Class, ' + featureClass + ', does not exist...')
&amp;nbsp;&amp;nbsp; 
&amp;nbsp; else: # feature class exists, continue...
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; ## Do calculations here...
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; # don't know how you want to write the results, you could use an insert cursor
&amp;nbsp;&amp;nbsp; #&amp;nbsp; or copy selected rows to a new table (or the new table...)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Good luck!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Stacy&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 23:36:35 GMT</pubDate>
    <dc:creator>StacyRendall1</dc:creator>
    <dc:date>2021-12-10T23:36:35Z</dc:date>
    <item>
      <title>Searching for relate cursor example in Python</title>
      <link>https://community.esri.com/t5/python-questions/searching-for-relate-cursor-example-in-python/m-p/94401#M7369</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Folks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I've searched the archives and ESRI help for example code that does a relate using cursors and can't seem to find one. Here's my problem. Perhaps someone can share code or give an example of how you would code this? It seems like this should be simple enough...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a ArcGIS data table with an id code "parcelid". I thought that I would use a SearchCursor to walk through each row and then relate through "parcelid" to a featureclass to grab the records that match that parcelid. I then need to do a series of calculations on fields in the table and featureclass and put the result in a new table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any help would be greatly appreciated! Thanks, Holly&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 24 Jul 2011 13:59:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searching-for-relate-cursor-example-in-python/m-p/94401#M7369</guid>
      <dc:creator>HollyCopeland</dc:creator>
      <dc:date>2011-07-24T13:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for relate cursor example in Python</title>
      <link>https://community.esri.com/t5/python-questions/searching-for-relate-cursor-example-in-python/m-p/94402#M7370</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Holly, this should get you started... The #'s are Python comments...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What you do at the end (writing to new table) really depends on what you calculate and where it ends up. In this little example I created a table, but you could also copy rows or something like that.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, I haven't tested it out (there could be typo's, etc.).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;in_tablePath = arcpy.GetParameterAsText(0) # full path to input table (includes name)
out_tablePath = arcpy.GetParameterAsText(1) # path to output table
out_tableName = arcpy.GetParameterAsText(2) # name of output table
featureClass_dataset = arcpy.GetParameterAsText(3) # path to the .gdb (or Folder if .shp) of the feature classes

if not arcpy.Exists(in_tablePath): # check in case table doesn't exist...
 arcpy.AddError('Table, ' + in_tablePath + ', does not exist...')
 
else: # table does exist, continue
 arcpy.AddMessage('Using table: ' + in_tablePath) # let the user know the table path
 
 arcpy.CreateTable_management(out_tablePath, out_tableName) # create the output table...
 
 arcpy.AddField_management(out_tablePath+'\\'+out_tableName, "outputData", "DOUBLE") # add a field to the new table
 arcpy.CalculateField_management(out_tablePath+'\\'+out_tableName, "outputData", 0, "PYTHON") # calculate its value as 0 for now... (optional)
 
 rowList = arcpy.SearchCursor(in_tablePath)
 for row in rowList: # for every row
&amp;nbsp; 
&amp;nbsp; parcelID = row.getValue("parcelid")
&amp;nbsp; 
&amp;nbsp; # i.e. if the feature classes are in C:\GIS\Data\parcels.gdb, and parcelID = 7
&amp;nbsp; #&amp;nbsp; will return the feature class C:\GIS\Data\parcels.gdb\7
&amp;nbsp; featureClass = featureClass_dataset + '\\' + str(parcelID) # make sure parcelID is changed to a string as well
&amp;nbsp; 
&amp;nbsp; if not arcpy.Exists(featureClass): # check in case feature class doesn't exist...
&amp;nbsp;&amp;nbsp; arcpy.AddError('Feature Class, ' + featureClass + ', does not exist...')
&amp;nbsp;&amp;nbsp; 
&amp;nbsp; else: # feature class exists, continue...
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; ## Do calculations here...
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; # don't know how you want to write the results, you could use an insert cursor
&amp;nbsp;&amp;nbsp; #&amp;nbsp; or copy selected rows to a new table (or the new table...)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Good luck!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Stacy&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:36:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searching-for-relate-cursor-example-in-python/m-p/94402#M7370</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2021-12-10T23:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: Searching for relate cursor example in Python</title>
      <link>https://community.esri.com/t5/python-questions/searching-for-relate-cursor-example-in-python/m-p/94403#M7371</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks, Stacy. I don't think the code you sent was quite what I was looking for (but I could be wrong as I am relatively new to Python). This code from a friend was more along the lines of what I needed. Thanks, though!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
arcpy.env.workspace = r'C:\WorkSpace\Projects\Code\Special Request\Copeland\src\SageGrouseTestCode.gdb'
parcelIDTable = 'ParcelNBTable'
lekFC = 'LekParcelFC'
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; parcelRows = arcpy.SearchCursor(parcelIDTable, "", "", "ParcelNBTable_PARCELNB", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; for parcelRow in parcelRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Parcel Number: %s' %parcelRow.ParcelNBTable_PARCELNB
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(parcelRow.ParcelNBTable_PARCELNB) &amp;gt; 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; expression = '"PARCELNB" = ' + "'" + parcelRow.ParcelNBTable_PARCELNB + "'"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lekRows = arcpy.SearchCursor(lekFC, expression, "", "", "Complex A")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lekRow in lekRows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print '\tLek complex name: %s\tCount %i' %(lekRow.Complex, lekRow.MAX_MostRecentPeakCount)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages(2)
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print arcpy.GetMessages(2)
print 'fin'&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:36:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/searching-for-relate-cursor-example-in-python/m-p/94403#M7371</guid>
      <dc:creator>HollyCopeland</dc:creator>
      <dc:date>2021-12-10T23:36:37Z</dc:date>
    </item>
  </channel>
</rss>

