<?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 FeatureClassToFeatureClass_conversion with only certain fields in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/featureclasstofeatureclass-conversion-with-only/m-p/713141#M55325</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Greetings,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am using FeatureClassToFeatureClass_conversion to export a new feature based on a selection. I would only like to carry over certain fields. Is this something that can be done?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It looks like it is done through the FieldMap parameter but I have never worked with FieldMap objects...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT: I've written this...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;fieldmappings = arcpy.FieldMap ()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fieldmappings.addInputField(thePoint, "POINTGUIDt")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fieldmappings.addInputField(thePoint, "S_FILE")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fieldmappings.addInputField(thePoint, "LINE_NBR")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;then try to use it here:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.FeatureClassToFeatureClass_conversion (thePoint, outDatabase, "PPMD_04V1i_" + envelopePolyTrim,"",fieldmappings)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and get this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\E1B8\ScriptTesting\SelectbyAttributeAndExport\Actual\ActualSelectbyAttributeAndExport.py", line 61, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.FeatureClassToFeatureClass_conversion (thePoint, outDatabase, "PPMD_04V1i_" + envelopePolyTrim,"",fieldmappings)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\conversion.py", line 1547, in FeatureClassToFeatureClass&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise e&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RuntimeError: Object: Error in executing tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Am I close? Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 13 Dec 2013 21:05:28 GMT</pubDate>
    <dc:creator>Emilbrundage</dc:creator>
    <dc:date>2013-12-13T21:05:28Z</dc:date>
    <item>
      <title>FeatureClassToFeatureClass_conversion with only certain fields</title>
      <link>https://community.esri.com/t5/python-questions/featureclasstofeatureclass-conversion-with-only/m-p/713141#M55325</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Greetings,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am using FeatureClassToFeatureClass_conversion to export a new feature based on a selection. I would only like to carry over certain fields. Is this something that can be done?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It looks like it is done through the FieldMap parameter but I have never worked with FieldMap objects...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT: I've written this...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;fieldmappings = arcpy.FieldMap ()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fieldmappings.addInputField(thePoint, "POINTGUIDt")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fieldmappings.addInputField(thePoint, "S_FILE")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fieldmappings.addInputField(thePoint, "LINE_NBR")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;then try to use it here:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.FeatureClassToFeatureClass_conversion (thePoint, outDatabase, "PPMD_04V1i_" + envelopePolyTrim,"",fieldmappings)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and get this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\E1B8\ScriptTesting\SelectbyAttributeAndExport\Actual\ActualSelectbyAttributeAndExport.py", line 61, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.FeatureClassToFeatureClass_conversion (thePoint, outDatabase, "PPMD_04V1i_" + envelopePolyTrim,"",fieldmappings)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\conversion.py", line 1547, in FeatureClassToFeatureClass&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise e&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RuntimeError: Object: Error in executing tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Am I close? Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Dec 2013 21:05:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/featureclasstofeatureclass-conversion-with-only/m-p/713141#M55325</guid>
      <dc:creator>Emilbrundage</dc:creator>
      <dc:date>2013-12-13T21:05:28Z</dc:date>
    </item>
    <item>
      <title>Re: FeatureClassToFeatureClass_conversion with only certain fields</title>
      <link>https://community.esri.com/t5/python-questions/featureclasstofeatureclass-conversion-with-only/m-p/713142#M55326</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think it would be a bit easier (or at least, just as thorough) to do this with a Make Feature Layer followed by a Select By Attribute followed by a Copy Features.&amp;nbsp; Try something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Make a feature layer of your input data, specifying only the fields you care about; this feature layer is stored in memory&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.MakeFeatureLayer_management(thePoint, "thePoint_selection", "", "", "POINTGUIDt POINTGUIt VISIBLE;S_FILE S_FILE VISIBLE;LINE_NBR LINE_NBR VISIBLE; OTHER_FIELD1 OTHER_FIELD1 HIDDEN; OTHER_FIELD2 OTHER_FIELD2 HIDDEN")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Create your selection set (assuming an attribute-based selection); the selection will persist in memory for subsequent tools while the script is still running&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management("thePoint_selection", "NEW_SELECTION", "SOME_FIELD &amp;gt; 10000")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Write the in-memory feature layer to a physical feature class in an output file geodatabase, which should copy over only the fields you specified from the Make Feature Layer tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CopyFeatures_management("thePoint_selection", "C:/E1B8/ScriptTesting/SelectbyAttributeAndExport/Actual/output.gdb/selection_set")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Dec 2013 22:49:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/featureclasstofeatureclass-conversion-with-only/m-p/713142#M55326</guid>
      <dc:creator>WilliamCraft</dc:creator>
      <dc:date>2013-12-13T22:49:17Z</dc:date>
    </item>
    <item>
      <title>Re: FeatureClassToFeatureClass_conversion with only certain fields</title>
      <link>https://community.esri.com/t5/python-questions/featureclasstofeatureclass-conversion-with-only/m-p/713143#M55327</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Your field mappings is not properly populated. There is no .&lt;/SPAN&gt;&lt;STRONG&gt;addInputField&lt;/STRONG&gt;&lt;SPAN&gt;(....) method on a FieldMappings object. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There are two ways you can populate an empty FieldMappings object:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. .addTable() method of &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/main/10.1/#/FieldMappings/018z00000078000000/" rel="nofollow" target="_blank"&gt;FieldMappings&lt;/A&gt;&lt;SPAN&gt; object - this is a wholesale course-grain approach - it adds all the fields of the table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Create &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/main/10.1/#/FieldMap/018z0000007p000000/" rel="nofollow" target="_blank"&gt;FieldMap&lt;/A&gt;&lt;SPAN&gt; object individually and then add the field map to FieldMappings object. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Code sample here:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/main/10.1/#/FieldMappings/018z00000078000000/" rel="nofollow" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.1/#/FieldMappings/018z00000078000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;See this image to find the difference between FieldMap and FieldMappings objects:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]29918[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would strongly encourage you to explore the field mapping mechanism as it is a "very powerful" tool to manipulate data. Once you spend some time you'll feel how easy it is to use &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Dec 2013 16:52:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/featureclasstofeatureclass-conversion-with-only/m-p/713143#M55327</guid>
      <dc:creator>NobbirAhmed</dc:creator>
      <dc:date>2013-12-16T16:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: FeatureClassToFeatureClass_conversion with only certain fields</title>
      <link>https://community.esri.com/t5/python-questions/featureclasstofeatureclass-conversion-with-only/m-p/713144#M55328</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the tips guys. I fumbled through it and got it to work with this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;fms = arcpy.FieldMappings()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;POINTGUIDt = arcpy.FieldMap ()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;POINTGUIDt.addInputField(thePoint, "POINTGUIDt")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fms.addFieldMap(POINTGUIDt)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;S_FILE = arcpy.FieldMap ()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;S_FILE.addInputField(thePoint, "S_FILE")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fms.addFieldMap(S_FILE)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;LINE_NBR = arcpy.FieldMap ()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;LINE_NBR.addInputField(thePoint, "LINE_NBR")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fms.addFieldMap(LINE_NBR)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.FeatureClassToFeatureClass_conversion (thePoint, outDatabase, "PPMD_04V1i_" + envelopePolyTrim,"",fms)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm not sure if it's the prettiest way to do it but it worked! Thanks again.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Dec 2013 16:57:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/featureclasstofeatureclass-conversion-with-only/m-p/713144#M55328</guid>
      <dc:creator>Emilbrundage</dc:creator>
      <dc:date>2013-12-16T16:57:30Z</dc:date>
    </item>
  </channel>
</rss>

