<?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: CalculateField based on attribute in another layer in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculatefield-based-on-attribute-in-another-layer/m-p/159963#M12249</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you have a unique field (other than the original OBJECTID), you can create a dictionary based on that {uniqueID vs originalOBJECTID} and after the export add the original OBJECTID based on the unique ID. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 24 Feb 2016 12:09:50 GMT</pubDate>
    <dc:creator>XanderBakker</dc:creator>
    <dc:date>2016-02-24T12:09:50Z</dc:date>
    <item>
      <title>CalculateField based on attribute in another layer</title>
      <link>https://community.esri.com/t5/python-questions/calculatefield-based-on-attribute-in-another-layer/m-p/159957#M12243</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I have list of layers from mxd save in a variable lyrs. I want to copy every layer to file gdb so I use for loop.&amp;nbsp; I need to preserve original OBJECTID in the new layers so I add a new field originOBJID into new layers. Is there any option/expression how to calculate field in new layer based on attribute OBJECTID from original layer (lyr in the for loop)??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;mxd=arcpy.mapping.MapDocument("path")&lt;/P&gt;&lt;P&gt;lyrs=arcpy.mapping.ListLayers(mxd)&lt;/P&gt;&lt;P&gt;for lyr in lyrs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; layr=arcpy.FeatureClassToFeatureClass_conversion(lyr,in_gdb,lyr.name)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(layr,"originOBJID","LONG")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(layr,"originOBJID","???")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot for help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Feb 2016 15:25:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculatefield-based-on-attribute-in-another-layer/m-p/159957#M12243</guid>
      <dc:creator>ZdeněkSoldán</dc:creator>
      <dc:date>2016-02-23T15:25:32Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateField based on attribute in another layer</title>
      <link>https://community.esri.com/t5/python-questions/calculatefield-based-on-attribute-in-another-layer/m-p/159958#M12244</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could always create a field to hold the &lt;SPAN style="color: #3d3d3d; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; font-size: 14px;"&gt;OBJECTID before you create the new feature classes&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Feb 2016 15:29:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculatefield-based-on-attribute-in-another-layer/m-p/159958#M12244</guid>
      <dc:creator>WesMiller</dc:creator>
      <dc:date>2016-02-23T15:29:53Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateField based on attribute in another layer</title>
      <link>https://community.esri.com/t5/python-questions/calculatefield-based-on-attribute-in-another-layer/m-p/159959#M12245</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unfortunately I can't. Original data are from SDE gdb connected through user without editing rights.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Feb 2016 15:33:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculatefield-based-on-attribute-in-another-layer/m-p/159959#M12245</guid>
      <dc:creator>ZdeněkSoldán</dc:creator>
      <dc:date>2016-02-23T15:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateField based on attribute in another layer</title>
      <link>https://community.esri.com/t5/python-questions/calculatefield-based-on-attribute-in-another-layer/m-p/159960#M12246</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could use a &lt;A href="http://desktop.arcgis.com/en/arcmap/10.3/tools/analysis-toolbox/spatial-join.htm" title="http://desktop.arcgis.com/en/arcmap/10.3/tools/analysis-toolbox/spatial-join.htm"&gt;Spatial Join—Help | ArcGIS for Desktop&lt;/A&gt; to get the oids and calculate them to your new feature class.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Feb 2016 15:52:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculatefield-based-on-attribute-in-another-layer/m-p/159960#M12246</guid>
      <dc:creator>WesMiller</dc:creator>
      <dc:date>2016-02-23T15:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateField based on attribute in another layer</title>
      <link>https://community.esri.com/t5/python-questions/calculatefield-based-on-attribute-in-another-layer/m-p/159961#M12247</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you be more specific how to use Spatial Join? I tried it but it didn't join OBJECTIDs from original layer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Feb 2016 06:50:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculatefield-based-on-attribute-in-another-layer/m-p/159961#M12247</guid>
      <dc:creator>ZdeněkSoldán</dc:creator>
      <dc:date>2016-02-24T06:50:57Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateField based on attribute in another layer</title>
      <link>https://community.esri.com/t5/python-questions/calculatefield-based-on-attribute-in-another-layer/m-p/159962#M12248</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok when I used ONE TO MANY method field join FID appeared in the new layer made by Spatial Join. But it doesn't solve my problem because this field is still in another layer than I need. I need all fields from layer created by &lt;SPAN style="color: #3d3d3d; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; font-size: 14px;"&gt;layr=arcpy.FeatureClassToFeatureClass_conversion(lyr,in_gdb,lyr.name) plus one new created originOBJID nothing more. And I can't use fieldmappings to remove duplicated fields because they have the same name.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; font-size: 14px;"&gt;So is there any option how to transfer needed field from another layer into calculate field and fill the field directly in the "layr" layer???&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Feb 2016 10:29:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculatefield-based-on-attribute-in-another-layer/m-p/159962#M12248</guid>
      <dc:creator>ZdeněkSoldán</dc:creator>
      <dc:date>2016-02-24T10:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateField based on attribute in another layer</title>
      <link>https://community.esri.com/t5/python-questions/calculatefield-based-on-attribute-in-another-layer/m-p/159963#M12249</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you have a unique field (other than the original OBJECTID), you can create a dictionary based on that {uniqueID vs originalOBJECTID} and after the export add the original OBJECTID based on the unique ID. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Feb 2016 12:09:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculatefield-based-on-attribute-in-another-layer/m-p/159963#M12249</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2016-02-24T12:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateField based on attribute in another layer</title>
      <link>https://community.esri.com/t5/python-questions/calculatefield-based-on-attribute-in-another-layer/m-p/159964#M12250</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes I have other unique field. Please would you be so kind and show me in more detail how to do this?&lt;/P&gt;&lt;P&gt;the other unique field is INVCIS&lt;/P&gt;&lt;P&gt;so I will create dictionary first after that export the layer and how then I add the field from dictionary to exportet layer?? By cursor? Can you please show me how to do that??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 14px; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; color: #3d3d3d;"&gt;Thank you very much&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Feb 2016 14:18:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculatefield-based-on-attribute-in-another-layer/m-p/159964#M12250</guid>
      <dc:creator>ZdeněkSoldán</dc:creator>
      <dc:date>2016-02-24T14:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: CalculateField based on attribute in another layer</title>
      <link>https://community.esri.com/t5/python-questions/calculatefield-based-on-attribute-in-another-layer/m-p/159965#M12251</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To explain a bit how you could do this see the code below:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;On line 8 and 9 you should specify the paths to the existing input and non-existing output featureclasses (see examples on lines 6 and 7&lt;/LI&gt;&lt;LI&gt;The code will generate a dictionary of the unique field INVCIS versus the original OBJECTID. See lines 15 - 17&lt;/LI&gt;&lt;LI&gt;Next the featureclass is converted to the output featureclass on line 21&lt;/LI&gt;&lt;LI&gt;On line 24 the additional field is added&lt;/LI&gt;&lt;LI&gt;Lines 27 - 36 update the output featureclass and write the original OBJECTID to the field called originOBJID&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy
&amp;nbsp;&amp;nbsp;&amp;nbsp; import os

&amp;nbsp;&amp;nbsp;&amp;nbsp; # paths to input and output featureclasses
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Database Connections\Desarrollo 10.1.sde\EPMGIS.DEPTO_TRANSPORTE\EPMGIS.DEPTO_Lyr_Via_Vehi
&amp;nbsp;&amp;nbsp;&amp;nbsp; # D:\Xander\GeoNet\3Dpoints_3Dlines\gdb\test.gdb\polylineZ
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc_in = r''
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc_out = r''

&amp;nbsp;&amp;nbsp;&amp;nbsp; fld_OIDout = 'originOBJID'
&amp;nbsp;&amp;nbsp;&amp;nbsp; fld_id = 'INVCIS'

&amp;nbsp;&amp;nbsp;&amp;nbsp; # generate dictionary (LUT)
&amp;nbsp;&amp;nbsp;&amp;nbsp; fld_OIDin = arcpy.Describe(fc_in).OIDFieldName
&amp;nbsp;&amp;nbsp;&amp;nbsp; flds = (fld_id, fld_OIDin)
&amp;nbsp;&amp;nbsp;&amp;nbsp; dct = {r[0]:r[1] for r in arcpy.da.SearchCursor(fc_in, (flds))}

&amp;nbsp;&amp;nbsp;&amp;nbsp; # transfer the data
&amp;nbsp;&amp;nbsp;&amp;nbsp; ws, fc_name = os.path.split(fc_out)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.FeatureClassToFeatureClass_conversion(fc_in, ws, fc_name)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Add the additional field
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(fc_out, fld_OIDout, "LONG")

&amp;nbsp;&amp;nbsp;&amp;nbsp; # Update the unformation
&amp;nbsp;&amp;nbsp;&amp;nbsp; flds = (fld_id, fld_OIDout)
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(fc_out, (flds)) as curs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curs:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uid = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if uid in dct:
&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; row[1] = dct[uid]
&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; # this should not happen
&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; row[1] = -1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; curs.updateRow(row)

if __name__ == '__main__':
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Question: if you have a unique field to start with, why would you want to hold a reference to the original OBJECTID?&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:26:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculatefield-based-on-attribute-in-another-layer/m-p/159965#M12251</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-11T08:26:02Z</dc:date>
    </item>
  </channel>
</rss>

