<?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: How do I get list of fields from feature class/shapefile using tool? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-do-i-get-list-of-fields-from-feature-class/m-p/335305#M26235</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;To list all the fields from your input featureclass, use &lt;/SPAN&gt;&lt;STRONG&gt;arcpy.Listfields&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try to debug the following code, you'll get a print statement with the name, alias, type, and length for each field from your input fc:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
fieldList = arcpy.ListFields(fc)
for field in fieldList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fname = field.name
&amp;nbsp;&amp;nbsp;&amp;nbsp; falias = field.aliasName
&amp;nbsp;&amp;nbsp;&amp;nbsp; ftype = field.type
&amp;nbsp;&amp;nbsp;&amp;nbsp; flength = field.length
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "%s \t %s \t %s \t %i" % (field.name, field.aliasName, field.type, field.length)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 15:53:10 GMT</pubDate>
    <dc:creator>ThaiTruong</dc:creator>
    <dc:date>2021-12-11T15:53:10Z</dc:date>
    <item>
      <title>How do I get list of fields from feature class/shapefile using tool?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-get-list-of-fields-from-feature-class/m-p/335303#M26233</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm making a custom tool that will allow the user to make many different changes to the fields of a chosen feature class or shapefile.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Part of my code is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;fc = arcpy.GetParameterAsText(0)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And then when I create the tool parameters I choose the Data Type as Data Element.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The next input I get from the user is the field from the fc that they want to use to copy data from into a new field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;copy_field = arcpy.GetParameterAsText(1)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For this parameter I've tried Field, Field Info and Field Mappings but none of them give me the fields of the inputted fc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How can I link this parameter to the first one to give me a list of the fields within the fc?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 May 2013 13:21:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-get-list-of-fields-from-feature-class/m-p/335303#M26233</guid>
      <dc:creator>IB1</dc:creator>
      <dc:date>2013-05-15T13:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get list of fields from feature class/shapefile using tool?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-get-list-of-fields-from-feature-class/m-p/335304#M26234</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Do you want the user to select the field(s) they want to use? If so, the Data Type would be 'Field' with MultiValue = 'Yes' (to allow for multiple selections) and Obtained From would be set to your input feature class. I would recomend that you set your input layer to be a Data Type of 'Feature Layer', that way users can drag layers into the tool from the ArcMap TOC.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you just want to list the fields in the input layer, it'd be something like this: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;print ",".join([field.name for field in arcpy.ListFields(inputLayer)])&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 May 2013 16:05:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-get-list-of-fields-from-feature-class/m-p/335304#M26234</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2013-05-15T16:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get list of fields from feature class/shapefile using tool?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-get-list-of-fields-from-feature-class/m-p/335305#M26235</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;To list all the fields from your input featureclass, use &lt;/SPAN&gt;&lt;STRONG&gt;arcpy.Listfields&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try to debug the following code, you'll get a print statement with the name, alias, type, and length for each field from your input fc:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
fieldList = arcpy.ListFields(fc)
for field in fieldList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fname = field.name
&amp;nbsp;&amp;nbsp;&amp;nbsp; falias = field.aliasName
&amp;nbsp;&amp;nbsp;&amp;nbsp; ftype = field.type
&amp;nbsp;&amp;nbsp;&amp;nbsp; flength = field.length
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "%s \t %s \t %s \t %i" % (field.name, field.aliasName, field.type, field.length)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:53:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-get-list-of-fields-from-feature-class/m-p/335305#M26235</guid>
      <dc:creator>ThaiTruong</dc:creator>
      <dc:date>2021-12-11T15:53:10Z</dc:date>
    </item>
  </channel>
</rss>

