<?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: Modifying Permanent Sort script by Chris Snyder in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675432#M22414</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Rich,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will post an update to acrscripts in the next few days. So as I understand, the requirements are:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. The user can select up to four fields to sort.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. The user can specify a new field name that will contain the original OID prior to sorting.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sound Good?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 03 Aug 2010 21:33:45 GMT</pubDate>
    <dc:creator>ChrisSnyder</dc:creator>
    <dc:date>2010-08-03T21:33:45Z</dc:date>
    <item>
      <title>Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675428#M22410</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Chris:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am not sure how best to contact you directly, but I have been trying to modify a script you wrote and posted on the public scripts page about a year ago. Your script permanently sorts a feature class or table to a new output feature class or table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have been trying to modify the script to optionally add a valid additional field of type Long to the output that will store a copy of the original data source's OID field values. Your script by default drops the original OID values from the output. However, I need these OID values where I want to join the output back to the source, but the data source has no other unique ID than the OID field and I cannot alter the source data schema. I have some code that basically works if I can assume that all OID fields are actually named "OBJECTID", but I do not think that is the case.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In VBA there are methods that can query a data source to confirm it has an OID and then get the OID field's name (which tells me there is more than one way these fields can be named). Is there anything equivalent in Python? Or how would you approach checking these two aspects of a data source to add appropriate error checking routines to your Python script to handle a subroutine like the one I want?&amp;nbsp; If the new subroutine works, I would always be able to optionally include a join field in my sorted output that would work with any source that has an OID value without ever having to modify the source schema.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the script and I hope you can help me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rich&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Aug 2010 03:42:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675428#M22410</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2010-08-03T03:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675429#M22411</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I may have answered my initial question.&amp;nbsp; I found that an output variable holding the describe information of my input feature class/table has a method called OIDFieldName that can extract the source OID field name.&amp;nbsp; That should be all I need in order to verify that an input has an OID field and to make sure that I transfer information from it using its proper OID field name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, I have a follow up question about ModelBuilder tools in general.&amp;nbsp; I noticed that when I use the tool Chris created for this script that whenever I choose an input feature class or table, an output feature class/table name is automatically created for the output parameter that appends "_sortrecords" to the original input name.&amp;nbsp; It also makes sure that the output name is unique within the output workspace by appending a number to the name if necessary.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How is the output name parameter automatically being populated by the tool?&amp;nbsp; I tried checking the script and every property tab for the tool, but I cannot see what is triggering this behavior.&amp;nbsp; I also don't see any evidence of a IGPFunction asociated with the tool.&amp;nbsp; I would like to know how to replicate this kind of behavior for other tools I might build or modify.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyone know how its done?&amp;nbsp; Thanks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rich&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Aug 2010 14:31:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675429#M22411</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2010-08-03T14:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675430#M22412</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Preserving the original OID is a good idea! And the .oidfieldname property is the right one to use...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The output names are given the default toll name suffix by the Toolbox GUI seemingly automatically now in v9.3+ (the default naming is not handled in a controlled fashion by the script of tool parameter settings). It wasn't this way pre-v9.2, and depending on how you look at it, it can be a good or bad thing. Personally I don't like it, since it seems to override the "default" parameter values that you assign in the tool setup dialog.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Aug 2010 16:02:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675430#M22412</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-08-03T16:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675431#M22413</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Chris:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the answers.&amp;nbsp; I can see your point about the auto fill-in behavior.&amp;nbsp; It could be annoying since I do not really know the conditions that trigger it and can't control when I want it or don't.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also should mention that I modified your script to support up to four (4) sort fields on the input source so that the sorting capabilities are equivalent to an Advanced Table Sort on a Tableview in 9.3.&amp;nbsp; That makes the tool more consistent and complimentary with the Desktop interface.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I do not want to publiish my version on the Scripts page, since my version really is mostly your code.&amp;nbsp; I would like to encourage you to publish a revision of your script to do these things for everyone interested.&amp;nbsp; If you think it would save you any time, I can forward you my version, but I am sure you can incorporate these revisions as well or better than I have.&amp;nbsp; However, either way, it would be nice if you could review my script modifications, since you understand what the overall script is doing and could provide me with some valuable feedback on whether I am using Python to its full potential.&amp;nbsp; I am just beginning to transition from VBA to Python and I really don't know the Python language or coding conventions that well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rich&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Aug 2010 16:59:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675431#M22413</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2010-08-03T16:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675432#M22414</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Rich,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will post an update to acrscripts in the next few days. So as I understand, the requirements are:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. The user can select up to four fields to sort.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. The user can specify a new field name that will contain the original OID prior to sorting.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sound Good?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Aug 2010 21:33:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675432#M22414</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-08-03T21:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675433#M22415</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Rich,&lt;BR /&gt;&lt;BR /&gt;I will post an update to acrscripts in the next few days. So as I understand, the requirements are:&lt;BR /&gt;&lt;BR /&gt;1. The user can select up to four fields to sort.&lt;BR /&gt;2. The user can specify a new field name that will contain the original OID prior to sorting.&lt;BR /&gt;&lt;BR /&gt;Sound Good?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Exactly.&amp;nbsp; Sounds great.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will be interested in comparing your final code to mine.&amp;nbsp; I expect I will learn a few more things I didn't know about Python.&amp;nbsp; Thanks for taking this on. Your original tool was cool, but this new version will be way cool!&amp;nbsp; :cool:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rich&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Aug 2010 23:11:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675433#M22415</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2010-08-03T23:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675434#M22416</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I guess the old ArcScripts site is now uneditable - Damn! Until I get a CodeGallery thing going, here's the new script/toolbox. Didn't do much extensivee bug testing - Let me know if you find any issues...&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I guess our posts just missed each other.&amp;nbsp; I tried to open your zip file to WinZip using IE8 and get an error message.&amp;nbsp; I tried Mozilla Firefox instead and that worked fine, for anyone else trying to download your file.&amp;nbsp; (I guess Microsoft is trying to protect me from myself again. &lt;span class="lia-unicode-emoji" title=":face_with_tongue:"&gt;😛&lt;/span&gt; )&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Aug 2010 23:24:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675434#M22416</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2010-08-03T23:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675435#M22417</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Didn't do much extensivee bug testing - Let me know if you find any issues...&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Chris:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The new script did what I requested, but I noticed you did not rewrite the portion of your error checking tests to ensure that duplicate field names were not entered into multiple Sort Field choices so that the test accounted for the new sort field parameter.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I rewrote the section beginning at line 133 as follows to both check for all possible field duplications and to brake it down into separate field tests to keep it more readable:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #make sure the same field isn't trying to be sorted twice
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (sortFieldName4 not in ["","#"," "] and (sortFieldName4 in [sortFieldName1,sortFieldName2,sortFieldName3])):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "ERROR: Duplicate field name in Sort Field #4.&amp;nbsp; Can't sort the same field twice! Exiting script..."; showPyError(); sys.exit()
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (sortFieldName3 not in ["","#"," "] and (sortFieldName3 in [sortFieldName1,sortFieldName2])):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "ERROR: Duplicate field name in Sort Field #3.&amp;nbsp; Can't sort the same field twice! Exiting script..."; showPyError(); sys.exit()
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (sortFieldName1 == sortFieldName2):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "ERROR: Duplicate field name in Sort Field #2.&amp;nbsp; Can't sort the same field twice! Exiting script..."; showPyError(); sys.exit()
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I noticed that when I just wanted to sort just two fields that I as long as I put the first sort field in the Sort Field #1 parameter I could add the second sort field to any of the other 3 sort field parameters (as long as I specified the sort order that paired with the sort field parameter I chose) and the script worked the same.&amp;nbsp; That is nice.&amp;nbsp; Also, thanks for the quick modification.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am still trying to understand the way the nested try and if block works in the section where you transferred the OID values.&amp;nbsp; Your code worked, but based on the comment above that section I would have thought that it would have thrown an error when the OIDFieldName tried to calculate to the output's true OIDFieldName and that the user provide OID field would not have been populated.&amp;nbsp; Obviously I made a wrong assumption somewhere, but where did I go wrong?&amp;nbsp; When both tables have a matching OID field name and the setvalue matches the names and attempts to overwrite the inserted record's true OID value, does that not cause an error?&amp;nbsp; Did I miss that somehow the code does not actually try to overwrite a true OID value in the output?&amp;nbsp; Please provide me with a little insight.&amp;nbsp; (Faulty assumptions like that can sometimes stick in my thinking and cause me to write unneeded code to work around a non-problem &lt;span class="lia-unicode-emoji" title=":face_with_open_mouth:"&gt;😮&lt;/span&gt; .)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rich&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:28:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675435#M22417</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-12T04:28:55Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675436#M22418</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Great - thanks for the error checking part - I will add that to my version.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The part where the OIDs get populated: The deal is that you can't populate some fields in a fc/table like OID, Length, Area, etc. That is what the "try" is for: Loop through the fieldList, and for each field, try to populate that field (but we can't for OID, Shape, etc). However, we can popualte the ORIG_OID field (whataver its called) and other fields since they are writable. I have some other logic in there for dealing with the 10 character limitation for .dbf/.shp files, and there probably is a better way to organize that, but... Also some logic for dealing with the ORIG_OID field if the user provided a field name, otherwise don't populate it (since we never added it in the 1st place).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Aug 2010 15:03:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675436#M22418</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-08-04T15:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675437#M22419</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I realized why the loop made no sense to me.&amp;nbsp; It is written so that every time the loop writes to a field that can have its value set, it also writes to the ouput OID field provided by the user (if the input has an OID field).&amp;nbsp; So if there are 10 writable fields, the user OID field is writen 10 times per record (more writeable fields only makes processing the loop worse due to twice as many write attempts).&amp;nbsp; My VBA training from ESRI on loops has taught me to place as much of my testable conditions outside of the loop as possible and then minimize writing to a cursor within the loop to maximize speed and efficiency.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To achieve those objectives I set some variables outside the loop that have pre-tested whether a write of the user provided OID field should even be attemped within the loop.&amp;nbsp; I then only attempt to write to the user field when the input OID field is being read from the input (if the input has no OID field the user provided field never gets a write attempt and a related warning is reported at the end).&amp;nbsp; All other non-OID fields being read from the input will bypass the user provided field and use your normal field writing code.&amp;nbsp; This revison of the loop results in only a single write attempt for each field in a record. This should definitely improve overall speed of the cursor writing process.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My revision of the loop is as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; inputLayerOidFieldName = dsc.oidfieldname
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Only attempt to write to the users OID field if the a field name is provided and the input has an OID field.
&amp;nbsp;&amp;nbsp;&amp;nbsp; if originalOidFieldName not in ["","#"," "] and inputLayerOidFieldName &amp;gt; " ":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tryOidFieldWrite = True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; origOidPopulateSuccessFlag = True
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tryOidFieldWrite = False
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; origOidPopulateSuccessFlag = False
&amp;nbsp;&amp;nbsp;&amp;nbsp; while searchRow:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insertRow = insertRows.newrow()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for fieldName in inputLayerFieldList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try: #you can't write the OID, length, area, etc. fields!
&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; if outShpDbfFlag == False:
&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; # Only attempt to write to the user OID field when the input OID field is being read
&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; if tryOidFieldWrite == True and inputLayerOidFieldName == fieldName:
&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;&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;&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; insertRow.setvalue(originalOidFieldName, searchRow.getvalue(inputLayerOidFieldName))
&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;&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;&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; origOidPopulateSuccessFlag = False
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass
&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; # All fields other than the input OID field are passed to this code.&amp;nbsp; The input OID will also be passed if the user did not provide an output OID field name, but being non-writable it will fail.
&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; else:
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insertRow.setvalue(fieldName, searchRow.getvalue(fieldName))
&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; else:
&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; # Only attempt to write to the user OID field when the input OID field is being read
&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; if tryOidFieldWrite == True and inputLayerOidFieldName == fieldName:
&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;&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;&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; insertRow.setvalue(originalOidFieldName[0:10], searchRow.getvalue(inputLayerOidFieldName))
&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;&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;&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; origOidPopulateSuccessFlag = False
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass
&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; # All fields other than the input OID field are passed to this code.&amp;nbsp; The input OID will also be passed if the user did not provide an output OID field name, but being non-writable it will fail.
&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; else:
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insertRow.setvalue(fieldName[0:10], searchRow.getvalue(fieldName))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; recordCount = recordCount + 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insertRows.insertrow(insertRow)&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; searchRow = searchRows.next()

&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "Successfully wrote " + str(recordCount) + " records!"; showPyMessage()
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Only publish a warning if the OID field write attempt should have been made and failed or if the user provided a field but the input had no OID field.
&amp;nbsp;&amp;nbsp;&amp;nbsp; if originalOidFieldName not in ["","#"," "] and tryOidFieldWrite == True and origOidPopulateSuccessFlag == False:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "WARNING: For some reason, the original OIDs could not be preserved in the output!"; showPyWarning()
&amp;nbsp;&amp;nbsp;&amp;nbsp; if originalOidFieldName not in ["","#"," "] and tryOidFieldWrite == False:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; message = "WARNING: The input had no OID field and could not be preserved in the output!"; showPyWarning()
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope that these revisions meet with your approval and can be incorporated into your final code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rich&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:28:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675437#M22419</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-12T04:28:58Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675438#M22420</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Rich,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You are totally correct! Great observation... I thought it seemed like when I was testing this stuff yesterday it was running a bit slow when I used the ORIG_OID option... Another idea to structure it would be to append the ORIG_OID field (if the user provides it) to the inputLayerFieldList, and then have a condition in the loop that says if inputLayerField == originalOidFieldName, then attempt to write it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Aug 2010 20:05:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675438#M22420</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-08-04T20:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675439#M22421</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I wanted to also modify the loop processing to implement a standard ArcObjects practice, but I do not know if Python supports it.&amp;nbsp; In ArcObjects it is much more efficient to use a field's index number that indicates the field's relative numeric position in the table rather than its field name to read and write data.&amp;nbsp; The reason is that when a field name is passed to ArcObject methods that use a field name, the method in the background processes an invisible loop through the table schema to get at a field's index position.&amp;nbsp; However, by using methods that directly use the field index number a loop is not triggered and it operates more like accessing an array element with an index value.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It is a standard practice in ArcObjects to speed up loops using dual cursors to first match up the input and output field names to obtain a key pair array of field index values outside of the loop.&amp;nbsp; Then within the loop the key pair indexes are used as directly as possible and methods that trigger the field name/field schema matching hidden loop are avoided.&amp;nbsp; Using the preloop matched field index directly in ArcObjects can speed up cursor get and set value operations by a factor that averages the number of fields divided by 2.&amp;nbsp; The effect on performance becomes very pronounced in a loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there anything equivalent in Python that will provide and use a field index value with a cursor rather than a field name?&amp;nbsp; If not I believe all loops with get and set value cursor operations that use a field name in reality are processing two loops (and getting an increased hit as fields toward the end of the schema are accessed).&amp;nbsp; If no similar field index capability exists for Python, that might provide a partial explanation for the attrocious performance of Python on joined tables as opposed to VBA or VB Script in the ModelBuilder field calculator.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rich&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Aug 2010 20:06:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675439#M22421</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2010-08-04T20:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675440#M22422</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Wow that's good info! So I do know of a way to get the field's index via Python, but it's slow and hokey, and you have to use a featurelayer or tableview as input. For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.makefeaturelayer(fc,"fl")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print gp.describe("fl").fieldinfo.findfieldbyname("TER_ID")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;6 #that is to say TER_ID is the 7th field, 0 being the 1st.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, I don't think there is a way to retrieve a field value in a cursor using it's index value. Maybe I'm wrong though... Seems that would be a major performance enhancement like you said. I have mostly shied away from embedded cursors (current script being an exception) since they tend to be slow.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One thing I have used a lot (and that could be useful here if the table wasn't too huge and you didn't care to transfer the geometry) is using a Python Dictionary object to emulate a table structure in memory. Once you have loaded a table into a dictionary (using a searchcursor) it is EXTREEMLY fast to access the field values. This is especially useful to when you have a need to constantly look up lots and lots of unordered values. For example, I wrote a script that performs traces of a stream network (created using the hydrology tools). The idea is that every arc is flowing downhill, so has a startnode that is upstream of the endnode. The basic approach I took was to load the OIDs and their start/end nodes into a dictionary. Then (if tracing downstream) I basically traverse the items in the dictionary, looking up the arcs end node, searching for an arc that has its startnode == the last end node and so on. See: &lt;/SPAN&gt;&lt;A href="http://forums.esri.com/thread.asp?t=275202&amp;amp;f=1729&amp;amp;c=93#948148" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.esri.com/thread.asp?t=275202&amp;amp;f=1729&amp;amp;c=93#948148&lt;/A&gt;&lt;SPAN&gt; for the code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A simple dictionary example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;lookupDict = {}
searchRows = gp.searchcursor(lookupTbl)
searchRow = searchRows.next()
while searchRow:
&amp;nbsp;&amp;nbsp; lookupDict[searchRow.LOOKUPITEM] = [searchRow.FIELDVALUE1,searchRow.FIELDVALUE2]
&amp;nbsp;&amp;nbsp; searchRow = searchRows.next()
del searchRow
del searchRows

updateRows = gp.updatecursor(tableToUpdateTbl)
updateRow = updateRows.next()
while updateRow:
&amp;nbsp;&amp;nbsp; updateRow.MEAN = (lookupDict[updateRow.LOOKUPITEM][0] + lookupDict[updateRow.LOOKUPITEM][1]) / 2
&amp;nbsp;&amp;nbsp; updateRows.UpdateRow(updateRow)
&amp;nbsp;&amp;nbsp; updateRow = updateRows.next()
del updateRow
del updateRows
del lookupDict&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:29:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675440#M22422</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-12T04:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675441#M22423</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Rich,&lt;BR /&gt;&lt;BR /&gt;You are totally correct! Great observation... I thought it seemed like when I was testing this stuff yesterday it was running a bit slow when I used the ORIG_OID option... Another idea to structure it would be to append the ORIG_OID field (if the user provides it) to the inputLayerFieldList, and then have a condition in the loop that says if inputLayerField == originalOidFieldName, then attempt to write it.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I perfer my version, because it allows me to distinguish three cases:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. No user OID field name provided.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. User OID field provided but no input OID available&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. User OID field provided, input OID available, but write attempt fails anyway.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Case 2 might not be anticipated by the user.&amp;nbsp; Case 3 is especially likely to happen when a geodatabase is being ported to a .dbf or .shp file and field name truncations do not match the way the schema was imported into the output feature class/table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Case 3 could also occur because the code currently does not test if the user provided a valid field against the output data source, which could happen if the user unknowingly uses a data source keyword or included spaces in the name or something else.&amp;nbsp; A gp.ValidateFieldName probably should be used in the code and if a different name is returned by that tool the new name should be appended to the output table and the user should be warned about the field name transformation.&amp;nbsp; This report would also help for the possible errors in field tranferrance that may result from trucating field names in and geodatabase to .dbf and .shp file transformations.&amp;nbsp; The appended user OID would still allow the user to join and manually transfer any missed field data to the output when they determined there was a failure that cannot be remedied with the current implementation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope this helps.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rich&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Aug 2010 20:42:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675441#M22423</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2010-08-04T20:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675442#M22424</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Jinx posting. Look at my post right above yours concerning dictionaries. This is all great stuff - I'm a hack self-taught programmer, so it's great to get someone else's suggestions, tips, tricks, etc.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Aug 2010 20:48:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675442#M22424</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-08-04T20:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675443#M22425</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;However, I don't think there is a way to retrieve a field value in a cursor using it's index value. Maybe I'm wrong though... Seems that would be a major performance enhancement like you said. I have mostly shied away from embedded cursors (current script being an exception) since they tend to be slow.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Your current code only creates a hit that is about twice as bad as using a single cursor since you are not really doing a record match on both sides of the cursors.&amp;nbsp; You are just reading a record on one side and writing a new record on the other.&amp;nbsp; The practice I mentioned for ArcObjects should still dramatically speed performance for a single cursor and for this kind of simple embedded cursor pair if Python had an efficient way to implement it.&amp;nbsp; However, for truly embedded cursor routines that have to look up records against each other or walk through a sorted pair of cursors (using multi-field keys especially), the primary hit is from maintaining the secondary query synchronization on unsorted records or records that are only sorted in memory.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Your tool that permanently sorts to a new table (without reordering fields on the original to use a summary/frequency) offers me the potential to solve the dual cursor synchronization issue, which was partly why I am so interested in it.&amp;nbsp; Developing an efficient way to do a single pass on a pair of cursors against tables with permanently sorted records could speed up the embedded cursors significantly.&amp;nbsp; By operating on all fields at once in a record with the cursor pair I should be able to be much more efficient than using the field calculator on a pair of joined tables operating one field at a time (recognizing that there are diminishing returns as I need to do this with fewer fields).&amp;nbsp; The OID addition I requested means that by doing a second sort back to original OID order I could use the same technique to transfer the data back to the original data source (without having to do a memory based sort).&amp;nbsp; Linking back to the original is particularly important to me where the original cannot be overwritten because it has topologies, feature linked annotation or other advanced features (or I do not control the original data but need to maintain a duplicate that can use these techiniques to extend and enhance the source data with data that I maintain).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The dictionary approach is valuable when the spatial information does not need to be taken into consideration.&amp;nbsp; Unfortunately, the spatial data almost always plays a roll in my cursor routines.&amp;nbsp; In my case I may use Visual Studio to do the embedded cursor work (or I might port your Python code to Visual Studio and see if I can get a substantial performance gain using an ArcObject cursor method I described above).&amp;nbsp; I am not really comfortable porting my VBA to Visual Studio either, but if I am going to have to do another learning curve I want others to benefit (like I have from this exchange).&amp;nbsp; Anyway, thanks for pointing me in a new direction that I think really begins to tackle some of the problems I am trying to solve.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(Edit) Actually, the dictionary approach may offer some interesting possibilies for me since I am in Transportation and most of my problems relate to traversing line networks in different ways.&amp;nbsp; Linear referencing has solved some of my problems, but it would be nice to create efficient cursor routines that can quickly traverse Route IDs and measure values on joined event tables of different inventories (signals, signs, curb ramps, accidents) and perform sophisticated analysis for output to a summary table.&amp;nbsp; My bosses would like to do segment analysis based on 1000 intervals or between interesections and I don't see a way to really do it without some kind of cursor operation.&amp;nbsp; Route IDs and measures provide me with a way to understand direction of travel and network traversal without usiing the shapes (if used together with an X/Y coordinate the analysis possibilities become very interesting).&amp;nbsp; Trying to train the computer to talk with end user data and needs is where I spend a lot of my time.&amp;nbsp; Anyway, ordering data seems to be the biggest factor in making these routines really perform well so this is a subject near and dear to my heart.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Rich&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Aug 2010 21:22:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675443#M22425</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2010-08-04T21:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675444#M22426</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Jinx posting. Look at my post right above yours concerning dictionaries. This is all great stuff - I'm a hack self-taught programmer, so it's great to get someone else's suggestions, tips, tricks, etc.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Double jinx posting.&amp;nbsp; My background is the same.&amp;nbsp; I am not part of IT.&amp;nbsp; I'm just a guy who wants to get the job done and transform the way my Department sees and does things through GIS.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Aug 2010 21:36:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675444#M22426</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2010-08-04T21:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675445#M22427</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;However, for truly embedded cursor routines that have to look up records against each other or walk through a sorted pair of cursors (using multi-field keys especially), the primary hit is from maintaining the secondary query synchronization on unsorted records or records that are only sorted in memory.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This is a great description of the case where the dictionary structure is so fast/usefull!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Aug 2010 21:39:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675445#M22427</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-08-04T21:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675446#M22428</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Holy crap! Rich, you got me thinking here and check this out. I had no idea you could do this (load the geometry object ito a dictionary so easily). Not sure how to use it, but that so damn cool!!! basically this way you could store an entire FC as a Python dictionary! Wow!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;dict = {}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; searchRows = gp.searchcursor(fc)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; searchRow = searchRows.next()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; dict[0] = searchRow.Shape&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; dict&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{0: &amp;lt;geoprocessing describe geometry object object at 0x00C1AAE8&amp;gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; del searchRow&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; del searchRows&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; dict[0].getpart(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;geoprocessing array object object at 0x00C1A890&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; dict[0].getpart(0).next().x&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;820175.92491082847&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Aug 2010 21:45:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675446#M22428</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-08-04T21:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying Permanent Sort script by Chris Snyder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675447#M22429</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Rich, you will like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcgisscripting
gp = arcgisscripting.create(9.3)
fc = r"D:\csny490\oesf_nso_models_20100623\landscape_model\results\results_bu.gdb\summary_results"
fieldList = gp.listfields(fc)
fieldIndex = 0
fieldNameDict = {}
for field in fieldList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldNameDict[field.name] = fieldIndex
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldIndex = fieldIndex + 1
fcDictionary = {}
oidFieldName = gp.describe(fc).oidfieldname
searchRows = gp.searchcursor(fc)
searchRow = searchRows.next()
while searchRow:
&amp;nbsp;&amp;nbsp;&amp;nbsp; recordReadCount = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp; oidFieldValue = searchRow.getvalue(oidFieldName)
&amp;nbsp;&amp;nbsp;&amp;nbsp; fcDictionary[oidFieldValue] = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; for field in fieldList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fcDictionary[oidFieldValue].append(searchRow.getvalue(field.name))
&amp;nbsp;&amp;nbsp;&amp;nbsp; searchRow = searchRows.next()
del searchRow
del searchRows

#Now that it's in the memory, fetch the habitat density field value of OID = 31 and its width...
fcDictionary[31][fieldNameDict["HAB_DENSITY"]] + " - " + str(fcDictionary[31][fieldNameDict["Shape"]].extent.width) + " feet wide!"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:29:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/modifying-permanent-sort-script-by-chris-snyder/m-p/675447#M22429</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-12T04:29:04Z</dc:date>
    </item>
  </channel>
</rss>

