<?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: Get the OID of a selected record? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/get-the-oid-of-a-selected-record/m-p/652314#M50803</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you Chris and Rhett! You guys are awesome!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 12 Jul 2013 18:44:58 GMT</pubDate>
    <dc:creator>ionarawilson1</dc:creator>
    <dc:date>2013-07-12T18:44:58Z</dc:date>
    <item>
      <title>Get the OID of a selected record?</title>
      <link>https://community.esri.com/t5/python-questions/get-the-oid-of-a-selected-record/m-p/652310#M50799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I need to have a record selected for the user to enter some attributes, then I need to deselect to calculate a unique id for the record (I only know how to calculate the unique id for all the records and that;s why I need to deselect it), then I need to continue updating that record that was selected before. For that I need to capture the OID of the selected record before I deselect it. I was able to write something to get the OID, but it gets the OID for all the records. Does anybody know how to get the OID for just the selected record? Thank you! Here is my snippet: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create search cursor for feature class. &amp;nbsp;&amp;nbsp;&amp;nbsp; rows = gp.SearchCursor("Stewardship") &amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.Next() &amp;nbsp;&amp;nbsp;&amp;nbsp; while row: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get the ID value &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = arcpy.Describe("Stewardship") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OIDFieldName = desc.OIDFieldName &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; id = row.GetValue(OIDFieldName) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(id) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row = rows.next() &lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jul 2013 12:55:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-the-oid-of-a-selected-record/m-p/652310#M50799</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2013-07-09T12:55:59Z</dc:date>
    </item>
    <item>
      <title>Re: Get the OID of a selected record?</title>
      <link>https://community.esri.com/t5/python-questions/get-the-oid-of-a-selected-record/m-p/652311#M50800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Never mind, this works if I have only one selected! Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Jul 2013 13:03:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-the-oid-of-a-selected-record/m-p/652311#M50800</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2013-07-09T13:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: Get the OID of a selected record?</title>
      <link>https://community.esri.com/t5/python-questions/get-the-oid-of-a-selected-record/m-p/652312#M50801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;glad to see you got it working.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I noticed that you have:&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = arcpy.Describe("Stewardship")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OIDFieldName = desc.OIDFieldName&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;within the while loop.&amp;nbsp; the Describe function can be pretty intensive operation and I don't see a need to set it within the loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I suspect it would run considerably faster if you were to move these two lines above and out of the while loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:39:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-the-oid-of-a-selected-record/m-p/652312#M50801</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2021-12-12T03:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: Get the OID of a selected record?</title>
      <link>https://community.esri.com/t5/python-questions/get-the-oid-of-a-selected-record/m-p/652313#M50802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Two other ways to get a list of OIDs of selected records (method #2 is the best BTW):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Method1: Must have a &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;selection&lt;/SPAN&gt;&lt;SPAN&gt; on the feature layer for this to work... but works in any version&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fc = r"C:\csny490\overlay_20130620\gis_layers\county.gdb\county"
arcpy.MakeFeatureLayer_management(fc, "fl")
arcpy.SelectLayerByAttribute_management("fl", "NEW_SELECTION", "COUNTY_CD &amp;gt; 10")
oidList = [int(oid) for oid in arcpy.Describe("fl").FIDSet.split(";")]&lt;/PRE&gt;&lt;SPAN&gt;#Method2: Uber fast! Works with a feature layer with a definition query and/or selected set... but only in v10.1+!&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fc = r"C:\csny490\overlay_20130620\gis_layers\county.gdb\county"
arcpy.MakeFeatureLayer_management(fc, "fl", "COUNTY_CD &amp;gt; 10")
oidList = [oid[0] for oid in arcpy.da.SearchCursor("fl",["OID@"])]&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:39:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-the-oid-of-a-selected-record/m-p/652313#M50802</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-12T03:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: Get the OID of a selected record?</title>
      <link>https://community.esri.com/t5/python-questions/get-the-oid-of-a-selected-record/m-p/652314#M50803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you Chris and Rhett! You guys are awesome!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Jul 2013 18:44:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-the-oid-of-a-selected-record/m-p/652314#M50803</guid>
      <dc:creator>ionarawilson1</dc:creator>
      <dc:date>2013-07-12T18:44:58Z</dc:date>
    </item>
  </channel>
</rss>

