<?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 How to: add field, then calculate same field with name of feature class in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/how-to-add-field-then-calculate-same-field-with/m-p/179675#M6019</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This question has come up a lot, but I am struggling to find a working solution to what should be a simple problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scenario:&lt;/P&gt;&lt;P&gt;I have a file geodatabase with 100 feature classes.&lt;/P&gt;&lt;P&gt;I want to add a field to each feature class and call it "Name"&lt;/P&gt;&lt;P&gt;I then want to calculate the field "Name" with the actual name of the feature class, for each feature class in the geodatabase.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not a whiz at python and model builder, but have more luck with the latter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've seen a few suggestions in other forums to use VB Script in the field calculator and have for example:&lt;/P&gt;&lt;P&gt;Name = "%Name%" , however this seems to produce a field that is populated with "%Name%" instead of the actual name of the feature class.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 10 Feb 2016 06:02:54 GMT</pubDate>
    <dc:creator>JustinOdell</dc:creator>
    <dc:date>2016-02-10T06:02:54Z</dc:date>
    <item>
      <title>How to: add field, then calculate same field with name of feature class</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/how-to-add-field-then-calculate-same-field-with/m-p/179675#M6019</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This question has come up a lot, but I am struggling to find a working solution to what should be a simple problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scenario:&lt;/P&gt;&lt;P&gt;I have a file geodatabase with 100 feature classes.&lt;/P&gt;&lt;P&gt;I want to add a field to each feature class and call it "Name"&lt;/P&gt;&lt;P&gt;I then want to calculate the field "Name" with the actual name of the feature class, for each feature class in the geodatabase.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not a whiz at python and model builder, but have more luck with the latter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've seen a few suggestions in other forums to use VB Script in the field calculator and have for example:&lt;/P&gt;&lt;P&gt;Name = "%Name%" , however this seems to produce a field that is populated with "%Name%" instead of the actual name of the feature class.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Feb 2016 06:02:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/how-to-add-field-then-calculate-same-field-with/m-p/179675#M6019</guid>
      <dc:creator>JustinOdell</dc:creator>
      <dc:date>2016-02-10T06:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to: add field, then calculate same field with name of feature class</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/how-to-add-field-then-calculate-same-field-with/m-p/179676#M6020</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Check this link.&lt;/P&gt;&lt;P&gt;&lt;A href="http://mappingcenter.esri.com/index.cfm?fa=ask.answers&amp;amp;q=1529" title="http://mappingcenter.esri.com/index.cfm?fa=ask.answers&amp;amp;q=1529"&gt;Esri Mapping Centre - Ask a Cartographer&lt;/A&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;To calculate the field with the feature class name, you need to parse the feature class path. &lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//004000000008000000.htm" target="_blank" title="ArcGIS Online Help: Parse Path"&gt;Parse Path&lt;/A&gt; is available as a model-specific tool. You can also use &lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/A_quick_tour_of_using_iterators_for_iteration_Looping/002w0000001w000000/" target="_blank" title="ArcGIS Online Help: A quick tour of using iterators for iteration—(Looping)"&gt;Iterators&lt;/A&gt; inside the model to loop through each of the feature classes.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;EDIT: You could also use the NAME variable in iterator, instead of PARSE PATH.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Feb 2016 06:12:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/how-to-add-field-then-calculate-same-field-with/m-p/179676#M6020</guid>
      <dc:creator>JayantaPoddar</dc:creator>
      <dc:date>2016-02-10T06:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to: add field, then calculate same field with name of feature class</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/how-to-add-field-then-calculate-same-field-with/m-p/179677#M6021</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When it comes to VBScript and ArcGIS, do what Nancy does, "just say no."&amp;nbsp; Model Builder has its place, it just isn't in my toolbox.&amp;nbsp; I encourage you to learn Python, it will open up ArcGIS to you much more than Model Builder, and the skills are infinitely more transferrable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The following should work for you.&amp;nbsp; Just paste the code into the interactive Python window and call the &lt;SPAN style="font-family: courier new,courier;"&gt;add_table_names&lt;/SPAN&gt; function with the geodatabase in question.&amp;nbsp; The script will find all tables and feature classes &lt;SPAN style="text-decoration: underline;"&gt;not in feature datasets&lt;/SPAN&gt; and append the name of the table or feature class as a new field.&amp;nbsp; If you want to recurse into the feature datasets, it isn't too hard to update the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def add_table_names(workspace):
&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = arcpy.Describe(workspace)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for child in desc.children:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if child.datasetType not in ('Table', 'FeatureClass'): continue
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(child.catalogPath, "FC_NAME", "TEXT")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(child.catalogPath,
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "FC_NAME",
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "'{}'".format(child.baseName),
&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "PYTHON_9.3")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:11:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/how-to-add-field-then-calculate-same-field-with/m-p/179677#M6021</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-11T09:11:45Z</dc:date>
    </item>
  </channel>
</rss>

