<?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: FieldMappings: Error in removing a field map from field mappings for RemoveFieldMap in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/fieldmappings-error-in-removing-a-field-map-from/m-p/97852#M7612</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is the error message: &lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "&amp;lt;interactive input&amp;gt;", line 8, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\arcobjects\arcobjects.py", line 336, in removeFieldMap&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return convertArcObjectToPythonObject(self._arc_object.RemoveFieldMap(*gp_fixargs(args)))&lt;/P&gt;&lt;P&gt;RuntimeError: FieldMappings: Error in removing a field map from field mappings for RemoveFieldMap&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I don't understand why can I remove a half of fields and only after that the error message appears.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 26 Jan 2016 11:54:16 GMT</pubDate>
    <dc:creator>ZdeněkSoldán</dc:creator>
    <dc:date>2016-01-26T11:54:16Z</dc:date>
    <item>
      <title>FieldMappings: Error in removing a field map from field mappings for RemoveFieldMap</title>
      <link>https://community.esri.com/t5/python-questions/fieldmappings-error-in-removing-a-field-map-from/m-p/97848#M7608</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;/P&gt;&lt;P&gt;I have a layer named patro_join with 114 fields and I want to preserve only two fields ("Layer","Text") in this layer. I tried to use FieldMappings but it removed only a half of fields and 57 fields still stay in the layer. I don´t know what is wrong. Here is my part of code: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fieldmappings = arcpy.FieldMappings()&lt;/P&gt;&lt;P&gt;fieldmappings.addTable("patro_join") &lt;/P&gt;&lt;P&gt;i=0&lt;/P&gt;&lt;P&gt;for field in fields:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if field.getInputFieldName(0) == "Layer": &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print field.getInputFieldName(0)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif field.getInputFieldName(0) == "Text":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print field.getInputFieldName(0)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print field.getInputFieldName(0)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldmappings.removeFieldMap(i)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i=i+1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone help me please?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Jan 2016 09:21:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/fieldmappings-error-in-removing-a-field-map-from/m-p/97848#M7608</guid>
      <dc:creator>ZdeněkSoldán</dc:creator>
      <dc:date>2016-01-26T09:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: FieldMappings: Error in removing a field map from field mappings for RemoveFieldMap</title>
      <link>https://community.esri.com/t5/python-questions/fieldmappings-error-in-removing-a-field-map-from/m-p/97849#M7609</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;dedent the i=i+1 line, it shouldn't line up with the line above, but with the else otherwise, the i=i+1 doesn't get incremented properly&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;i = 0
for
&amp;nbsp;&amp;nbsp;&amp;nbsp; if .....
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do stuff
&amp;nbsp;&amp;nbsp;&amp;nbsp; elif.....
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do&amp;nbsp; other
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; done
&amp;nbsp;&amp;nbsp;&amp;nbsp; i = i+1&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:07:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/fieldmappings-error-in-removing-a-field-map-from/m-p/97849#M7609</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T06:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: FieldMappings: Error in removing a field map from field mappings for RemoveFieldMap</title>
      <link>https://community.esri.com/t5/python-questions/fieldmappings-error-in-removing-a-field-map-from/m-p/97850#M7610</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you but it doesn't solve my problem. I have still the same error message. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Jan 2016 11:14:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/fieldmappings-error-in-removing-a-field-map-from/m-p/97850#M7610</guid>
      <dc:creator>ZdeněkSoldán</dc:creator>
      <dc:date>2016-01-26T11:14:07Z</dc:date>
    </item>
    <item>
      <title>Re: FieldMappings: Error in removing a field map from field mappings for RemoveFieldMap</title>
      <link>https://community.esri.com/t5/python-questions/fieldmappings-error-in-removing-a-field-map-from/m-p/97851#M7611</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ahhh you are getting an error message...&lt;/P&gt;&lt;P&gt;Could you copy and paste it?&amp;nbsp; I thought it might be a problem with the "i" incrementation.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Jan 2016 11:37:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/fieldmappings-error-in-removing-a-field-map-from/m-p/97851#M7611</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-01-26T11:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: FieldMappings: Error in removing a field map from field mappings for RemoveFieldMap</title>
      <link>https://community.esri.com/t5/python-questions/fieldmappings-error-in-removing-a-field-map-from/m-p/97852#M7612</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is the error message: &lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "&amp;lt;interactive input&amp;gt;", line 8, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\arcobjects\arcobjects.py", line 336, in removeFieldMap&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return convertArcObjectToPythonObject(self._arc_object.RemoveFieldMap(*gp_fixargs(args)))&lt;/P&gt;&lt;P&gt;RuntimeError: FieldMappings: Error in removing a field map from field mappings for RemoveFieldMap&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I don't understand why can I remove a half of fields and only after that the error message appears.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Jan 2016 11:54:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/fieldmappings-error-in-removing-a-field-map-from/m-p/97852#M7612</guid>
      <dc:creator>ZdeněkSoldán</dc:creator>
      <dc:date>2016-01-26T11:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: FieldMappings: Error in removing a field map from field mappings for RemoveFieldMap</title>
      <link>https://community.esri.com/t5/python-questions/fieldmappings-error-in-removing-a-field-map-from/m-p/97853#M7613</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1) What line of your code corresponds to: &lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;File "&amp;lt;interactive input&amp;gt;", line 8, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) Where do you populate the '&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;fields' variable?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3) Field maps could be replaced by an Append step in your code, create the template table with 2 fields within, and just use the append tool with Schema type set to "NO_TEST". &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;We dont have enough information to diagnose easily sorry!&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Jan 2016 13:21:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/fieldmappings-error-in-removing-a-field-map-from/m-p/97853#M7613</guid>
      <dc:creator>LukeWebb</dc:creator>
      <dc:date>2016-01-26T13:21:34Z</dc:date>
    </item>
    <item>
      <title>Re: FieldMappings: Error in removing a field map from field mappings for RemoveFieldMap</title>
      <link>https://community.esri.com/t5/python-questions/fieldmappings-error-in-removing-a-field-map-from/m-p/97854#M7614</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you only want to preserve a few fields, why don't you use the "Feature Class to Feature class" tool and only include the two fields you want to keep.&amp;nbsp;&amp;nbsp; &lt;A href="http://desktop.arcgis.com/en/desktop/latest/tools/conversion-toolbox/feature-class-to-feature-class.htm" title="http://desktop.arcgis.com/en/desktop/latest/tools/conversion-toolbox/feature-class-to-feature-class.htm"&gt;Feature Class To Feature Class—Help | ArcGIS for Desktop&lt;/A&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; This seems simpler than trying to delete a bunch of fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can run a test manually to get the format of the fields you need to keep (if you have to do this multiple times, so you need it in a script).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's a sample...&lt;/P&gt;&lt;P&gt;tool, before the delete....will delete all but PtID and the two elev_ fields&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image" height="306" src="https://community.esri.com/legacyfs/online/173739_pastedImage_1.png" style="width: 371px; height: 306.374px;" width="371" /&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-2 jive-image" height="314" src="https://community.esri.com/legacyfs/online/173740_pastedImage_2.png" style="width: 391px; height: 314.061px;" width="391" /&gt;&lt;/P&gt;&lt;P&gt;my new featureclass....&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-3 jive-image" height="445" src="https://community.esri.com/legacyfs/online/173747_pastedImage_3.png" style="height: 445px; width: 402.581px;" width="403" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The "code snippet" from the results tab....&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14538232683678740 jive_text_macro" data-renderedposition="1382.0333251953125_8_893_16" jivemacro_uid="_14538232683678740"&gt;&lt;P&gt;arcpy.FeatureClassToFeatureClass_conversion(in_features="C:/_beartest/Prep.gdb/Pts1_dd", out_path="C:/_beartest/Prep.gdb", out_name="testoutput", where_clause="", field_mapping="""PtID "Ptno" true true false 2 Short 0 0 ,First,#,C:\_beartest\Prep.gdb\Pts1_dd,PtID,-1,-1;elev_ft "elev_ft" true true false 2 Short 0 0 ,First,#,C:\_beartest\Prep.gdb\Pts1_dd,elev_ft,-1,-1;elev_m "elev_m" true true false 2 Short 0 0 ,First,#,C:\_beartest\Prep.gdb\Pts1_dd,elev_m,-1,-1""", config_keyword="")&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;....since the formatted snippet is off the screen...I'll include it as just the text.&amp;nbsp; Of course, you do not need the "fieldname=" in each of the arguments....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.FeatureClassToFeatureClass_conversion(in_features="C:/_beartest/Prep.gdb/Pts1_dd", out_path="C:/_beartest/Prep.gdb", out_name="testoutput", where_clause="", field_mapping="""PtID "Ptno" true true false 2 Short 0 0 ,First,#,C:\_beartest\Prep.gdb\Pts1_dd,PtID,-1,-1;elev_ft "elev_ft" true true false 2 Short 0 0 ,First,#,C:\_beartest\Prep.gdb\Pts1_dd,elev_ft,-1,-1;elev_m "elev_m" true true false 2 Short 0 0 ,First,#,C:\_beartest\Prep.gdb\Pts1_dd,elev_m,-1,-1""", config_keyword="")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sometimes you just need to sit back and see if there is a simpler way.&amp;nbsp; Hope this helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 Jan 2016 15:50:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/fieldmappings-error-in-removing-a-field-map-from/m-p/97854#M7614</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2016-01-26T15:50:07Z</dc:date>
    </item>
  </channel>
</rss>

