<?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 Using field info to only get certain fields in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-field-info-to-only-get-certain-fields/m-p/707271#M54797</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have&amp;nbsp; a feature class that I would like to export the attributes to Excel, while excluding certain fields. I know I could make a copy of the feature class and delete fields, but I would like to use the field info object to exclude the unnecessary fields while creating a table view. The following code still exports all the fields, can you tell me what I am missing?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After creating the table view I have tried, using copy rows instead of export to excel and got the same results. I also tried fieldinfo.removeField(index) for the fields I want to exclude but that returned an error (RuntimeError: ERROR 999999: Error executing function). Thanks for your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14165899193712534" jivemacro_uid="_14165899193712534"&gt;
&lt;P&gt;#---- Make Table View that only contains the needed fields and copy to Excel table&lt;/P&gt;
&lt;P&gt;# Get the fields from the input feature class&lt;/P&gt;
&lt;P&gt;fields= arcpy.ListFields(in_fc)&lt;/P&gt;
&lt;P&gt;# Create a fieldinfo object&lt;/P&gt;
&lt;P&gt;fieldinfo = arcpy.FieldInfo()&lt;/P&gt;
&lt;P&gt;# Iterate through the fields and set them to fieldinfo&lt;/P&gt;
&lt;P&gt;for field in fields:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # If field name is in list of fields to keep,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if field.name in out_fields:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Add to fieldinfo object&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldinfo.addField(field.name, &lt;SPAN style="color: rgba(0, 0, 0, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;field.name&lt;/SPAN&gt;, "VISIBLE", "")&lt;/P&gt;
&lt;P&gt;# Make the table view with only desired fields&lt;/P&gt;
&lt;P&gt;arcpy.MakeTableView_management(in_fc, "table_view", field_info = fieldinfo)&lt;/P&gt;
&lt;P&gt;# Copy to Excel table&lt;/P&gt;
&lt;P&gt;arcpy.TableToExcel_conversion("table_view", out_table)&lt;/P&gt;

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 21 Nov 2014 17:21:05 GMT</pubDate>
    <dc:creator>KristenE</dc:creator>
    <dc:date>2014-11-21T17:21:05Z</dc:date>
    <item>
      <title>Using field info to only get certain fields</title>
      <link>https://community.esri.com/t5/python-questions/using-field-info-to-only-get-certain-fields/m-p/707271#M54797</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have&amp;nbsp; a feature class that I would like to export the attributes to Excel, while excluding certain fields. I know I could make a copy of the feature class and delete fields, but I would like to use the field info object to exclude the unnecessary fields while creating a table view. The following code still exports all the fields, can you tell me what I am missing?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After creating the table view I have tried, using copy rows instead of export to excel and got the same results. I also tried fieldinfo.removeField(index) for the fields I want to exclude but that returned an error (RuntimeError: ERROR 999999: Error executing function). Thanks for your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14165899193712534" jivemacro_uid="_14165899193712534"&gt;
&lt;P&gt;#---- Make Table View that only contains the needed fields and copy to Excel table&lt;/P&gt;
&lt;P&gt;# Get the fields from the input feature class&lt;/P&gt;
&lt;P&gt;fields= arcpy.ListFields(in_fc)&lt;/P&gt;
&lt;P&gt;# Create a fieldinfo object&lt;/P&gt;
&lt;P&gt;fieldinfo = arcpy.FieldInfo()&lt;/P&gt;
&lt;P&gt;# Iterate through the fields and set them to fieldinfo&lt;/P&gt;
&lt;P&gt;for field in fields:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # If field name is in list of fields to keep,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if field.name in out_fields:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Add to fieldinfo object&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldinfo.addField(field.name, &lt;SPAN style="color: rgba(0, 0, 0, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;field.name&lt;/SPAN&gt;, "VISIBLE", "")&lt;/P&gt;
&lt;P&gt;# Make the table view with only desired fields&lt;/P&gt;
&lt;P&gt;arcpy.MakeTableView_management(in_fc, "table_view", field_info = fieldinfo)&lt;/P&gt;
&lt;P&gt;# Copy to Excel table&lt;/P&gt;
&lt;P&gt;arcpy.TableToExcel_conversion("table_view", out_table)&lt;/P&gt;

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Nov 2014 17:21:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-field-info-to-only-get-certain-fields/m-p/707271#M54797</guid>
      <dc:creator>KristenE</dc:creator>
      <dc:date>2014-11-21T17:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using field info to only get certain fields</title>
      <link>https://community.esri.com/t5/python-questions/using-field-info-to-only-get-certain-fields/m-p/707272#M54798</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Kristen,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The Make Table View tool only hide the fields, it doesn't actually delete them.&amp;nbsp; What I would recommend doing is adding the '&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//001200000027000000"&gt;Table to Table&lt;/A&gt;' function to your script.&amp;nbsp; You can write the output to your &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//001w00000047000000"&gt;scratch geodatabase&lt;/A&gt;, and then export to excel.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Nov 2014 18:11:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-field-info-to-only-get-certain-fields/m-p/707272#M54798</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2014-11-21T18:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using field info to only get certain fields</title>
      <link>https://community.esri.com/t5/python-questions/using-field-info-to-only-get-certain-fields/m-p/707273#M54799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;True it only hides the fields, but then when I export to Excel shouldn't it only export the fields that are in the table view?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The end goal is to get to an Excel table. I could use the table to table tool and field mappings or copy the feature class and delete fields before exporting, but I was trying bypass making a new GIS file before exporting to Excel.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Nov 2014 18:33:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-field-info-to-only-get-certain-fields/m-p/707273#M54799</guid>
      <dc:creator>KristenE</dc:creator>
      <dc:date>2014-11-21T18:33:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using field info to only get certain fields</title>
      <link>https://community.esri.com/t5/python-questions/using-field-info-to-only-get-certain-fields/m-p/707274#M54800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unfortunately, hidden fields are still exported.&amp;nbsp; One advantage of writing the output from the Table to Table tool to the scratch geodatabase is that it will make your tool portable, because this location will always be available or created at execution time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Nov 2014 18:42:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-field-info-to-only-get-certain-fields/m-p/707274#M54800</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2014-11-21T18:42:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using field info to only get certain fields</title>
      <link>https://community.esri.com/t5/python-questions/using-field-info-to-only-get-certain-fields/m-p/707275#M54801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could also roll out your own using numpy there are tools for converting &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/NumPyArrayToTable/018w00000016000000/"&gt;numpy arrays to tables &lt;/A&gt;and &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/TableToNumPyArray/018w00000018000000/"&gt;tables to numpy arrays&lt;/A&gt; .... you then have complete control.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Nov 2014 19:42:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-field-info-to-only-get-certain-fields/m-p/707275#M54801</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-11-21T19:42:55Z</dc:date>
    </item>
  </channel>
</rss>

