<?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: Change field length using arcpy.FeatureClassToFeatureClass_conversion in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150761#M11670</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The following changes the length of the field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; inshp = "line"
... fms = arcpy.FieldMappings()
... fm = arcpy.FieldMap()
... fm.addInputField(inshp,"myField")
... newField = fm.outputField
... newField.length = 100
... fm.outputField = newField
... fms.addFieldMap(fm)
... arcpy.FeatureClassToFeatureClass_conversion(inshp, r'C:/junk', 'newshp', field_mapping=fms)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that you must make your changes in a new field object ("newField") rather than fm.outputField. I won't say I understand why this is, it just is. For example, this will not change the output field length, although I would have guessed, like you, that it should:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; inshp = "line"
... fms = arcpy.FieldMappings()
... fm = arcpy.FieldMap()
... fm.addInputField(inshp,"myField")
... fm.outputField.length = 100
... fms.addFieldMap(fm)
... arcpy.FeatureClassToFeatureClass_conversion(inshp, r'C:/junk', 'newshp2', field_mapping=fms)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 08:07:09 GMT</pubDate>
    <dc:creator>DarrenWiens2</dc:creator>
    <dc:date>2021-12-11T08:07:09Z</dc:date>
    <item>
      <title>Change field length using arcpy.FeatureClassToFeatureClass_conversion</title>
      <link>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150755#M11664</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My goal is to take a shapefile, change the length of one of the text fields, and save a new shapefile using arcpy.FeatureClassToFeatureClass_conversion.&amp;nbsp; You can do it using the tool's interface, just add a shapefile to it and the fields are listed, right click on a field to change it's properties and change the field length, then save to a new shapefile.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But how to do that using code?&amp;nbsp; I think you have to manipulate the field mapping to do it, but I cannot seem to find where you make the change for a particular field.&amp;nbsp; So far I have:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; inshp = "c:/temp/test1.shp"&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; fms = arcpy.FieldMappings()&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; fms.addTable(inshp)&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; fms.fieldCount&lt;/P&gt;&lt;P&gt;6&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; fm = fms.getFieldMap(0)&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; fm.getInputFieldName(0)&lt;/P&gt;&lt;P&gt;u'CITY_NAME'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So how do I change the field length for the CITY_NAME field and save it back to the field mapping?&amp;nbsp; Once that is done, I guess you put the field mapping back into the tool:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.FeatureClassToFeatureClass_conversion(inshp, "c:/temp", "test2.shp", "", &lt;SPAN class="n"&gt;field_mapping&lt;/SPAN&gt;&lt;SPAN class="o"&gt;=&lt;/SPAN&gt;&lt;SPAN class="n"&gt;fms&lt;/SPAN&gt;&lt;SPAN class="p"&gt;&lt;/SPAN&gt;)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2015 18:20:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150755#M11664</guid>
      <dc:creator>MichaelCarson4</dc:creator>
      <dc:date>2015-05-14T18:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: Change field length using arcpy.FeatureClassToFeatureClass_conversion</title>
      <link>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150756#M11665</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why not take the output of your manual FC to FC conversion and copy it as a python snippet and see what is going on(Go to Geoprocessing Results, navigate to the process, right click and select copy as python snippet)?&amp;nbsp; From there it should be fairly easy to determine what changes you want to make and how to manipulate fields.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2015 18:44:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150756#M11665</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2015-05-14T18:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: Change field length using arcpy.FeatureClassToFeatureClass_conversion</title>
      <link>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150757#M11666</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have, but it does not tell me what code to use to make it that way! -mike&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2015 19:19:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150757#M11666</guid>
      <dc:creator>MichaelCarson4</dc:creator>
      <dc:date>2015-05-14T19:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: Change field length using arcpy.FeatureClassToFeatureClass_conversion</title>
      <link>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150758#M11667</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hmmm .... maybe a combination of&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/Add_Field/001700000047000000/"&gt;Add Field &lt;/A&gt;&amp;nbsp; ...&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/Calculate_Field/00170000004m000000/"&gt;Calculate field &lt;/A&gt; ...&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/Delete_Field/00170000004n000000/"&gt;Delete Field&lt;/A&gt; ...&lt;/P&gt;&lt;P&gt;and/or ...&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/Transpose_Fields/0017000000v4000000/"&gt;Transpose Fields&lt;/A&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;&lt;P&gt;will get you where you want since&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/Alter_Field/001700000198000000/"&gt;Alter Fields&lt;/A&gt;&amp;nbsp; only allows you to change the field name&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2015 19:42:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150758#M11667</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-05-14T19:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: Change field length using arcpy.FeatureClassToFeatureClass_conversion</title>
      <link>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150759#M11668</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Wow, that's a lot of tools to use!&amp;nbsp; I'm getting closer in my code, but cannot change the field length so far:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; fm.outputField.name&lt;/P&gt;&lt;P&gt;u'CITY_NAME'&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; fm.outputField.length&lt;/P&gt;&lt;P&gt;25&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; fm.outputField.length = 100&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; fm.outputField.length&lt;/P&gt;&lt;P&gt;25&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2015 20:13:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150759#M11668</guid>
      <dc:creator>MichaelCarson4</dc:creator>
      <dc:date>2015-05-14T20:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: Change field length using arcpy.FeatureClassToFeatureClass_conversion</title>
      <link>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150760#M11669</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;a couple of lines of code... to get you started&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="n"&gt;env&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;workspace&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="s"&gt;"C:/somefolder/a.gdb"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;AddField_management&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s"&gt;"some_layer"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="s"&gt;"cool_name"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="s"&gt;"DOUBLE"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="mi"&gt;12&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,6)&amp;nbsp;&amp;nbsp; # double field 12 wide 6 decimals&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;CalculateField_management&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s"&gt;"some_layer"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="s"&gt;"cool_name"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;, "!old_field!", &lt;SPAN class="s"&gt;"PYTHON_9.3"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="p"&gt;&lt;SPAN class="p"&gt;...&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="p"&gt;&lt;SPAN class="p"&gt;Etc&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="p"&gt;&lt;SPAN class="p"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2015 20:26:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150760#M11669</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-05-14T20:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: Change field length using arcpy.FeatureClassToFeatureClass_conversion</title>
      <link>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150761#M11670</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The following changes the length of the field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; inshp = "line"
... fms = arcpy.FieldMappings()
... fm = arcpy.FieldMap()
... fm.addInputField(inshp,"myField")
... newField = fm.outputField
... newField.length = 100
... fm.outputField = newField
... fms.addFieldMap(fm)
... arcpy.FeatureClassToFeatureClass_conversion(inshp, r'C:/junk', 'newshp', field_mapping=fms)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that you must make your changes in a new field object ("newField") rather than fm.outputField. I won't say I understand why this is, it just is. For example, this will not change the output field length, although I would have guessed, like you, that it should:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; inshp = "line"
... fms = arcpy.FieldMappings()
... fm = arcpy.FieldMap()
... fm.addInputField(inshp,"myField")
... fm.outputField.length = 100
... fms.addFieldMap(fm)
... arcpy.FeatureClassToFeatureClass_conversion(inshp, r'C:/junk', 'newshp2', field_mapping=fms)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:07:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150761#M11670</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T08:07:09Z</dc:date>
    </item>
    <item>
      <title>Re: Change field length using arcpy.FeatureClassToFeatureClass_conversion</title>
      <link>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150762#M11671</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Darren!&amp;nbsp; That does the trick and results in a shapefile with the one changed field.&amp;nbsp; If I want to bring over the others as is, I would loop through each to create a field map and then add them to the field mappings variable.&amp;nbsp; Then I would have a shapefile with all the fields and the one I changed too.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2015 21:35:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150762#M11671</guid>
      <dc:creator>MichaelCarson4</dc:creator>
      <dc:date>2015-05-14T21:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: Change field length using arcpy.FeatureClassToFeatureClass_conversion</title>
      <link>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150763#M11672</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/docs/DOC-2159"&gt;Mark a reply as the Correct Answer&lt;/A&gt;&amp;nbsp; &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2015 21:38:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150763#M11672</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-05-14T21:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: Change field length using arcpy.FeatureClassToFeatureClass_conversion</title>
      <link>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150764#M11673</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Done!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 May 2015 21:39:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-field-length-using-arcpy/m-p/150764#M11673</guid>
      <dc:creator>MichaelCarson4</dc:creator>
      <dc:date>2015-05-14T21:39:46Z</dc:date>
    </item>
  </channel>
</rss>

