Show Navigation | Hide Navigation
You are here:
Writing geoprocessing scripts > Scripting Object: Properties and methods > Properties and Methods

ListFields method

Release 9.1
Last modified August 19, 2005
E-mail This Topic Printable Version Give Us Feedback

Print all topics in : "Properties and Methods"

Related Topics

List all the fields in the specified table, feature class, or shapefile. Specifying search conditions (wildcard) and a field type will limit the results. This method and ListIndexes are the only two List methods that don’t require the user to preset the workspace.


object.ListFields(pInputValue, [wild card], [FieldType]) as Object

Returns a Dispatch enumeration object that will, in turn, hand out Dispatch Field objects.

Part Description
object The instantiated geoprocessing object
pInputValue The name, and/or path, of the table whose fields are to be listed
wild card Optional. Combination of * and characters that will help limit the results. The asterisk (*) is the same as saying ALL. If no wildcard is specified then all fields will be returned.
FieldType Optional. Keyword FieldType that will limit the returned fields. Valid FieldTypes for this method are:
  • SmallInteger—returns only fields of type Small Integer.
  • Integer—returns only fields of type Integer.
  • Single—returns only fields of type Single.
  • Double—returns only fields of type Double.
  • String—returns only fields of type String.
  • Date—returns only fields of type Date.
  • OID—returns only fields of type OID.
  • Geometry—returns only fields of type Geometry.
  • BLOB—returns only fields of type BLOB.
  • ALL—All fields will be selected. This is the default.

Field object properties

Name—returns the name

AliasName—returns the field alias name

Domain—returns the name of the associated domain

Editable—returns True if the field is editable

HasIndex—returns True if the field has an index

IsNullable—returns True if the field is nullable

IsUnique—returns True if the field is unique

Length—returns the length

Precision—returns the precision

Scale—returns the scale

Type—returns wither SmallInteger, Integer, Single, Double, String, Date, OID, Geometry, or BLOB

Field object property examples will be included below.


This script ensures that a field will be added, no matter what the input name is, using the ValidateFieldName method.

import win32com.client, sys, os
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")

# Check the number of arguments.
if len(sys.argv) < 2:
    print "Script requires two arguments, feature class and field name"
      # Get the input feature class and make sure it contains polygons.
      input = sys.argv[1]
      dsc = gp.Describe(input)
      if dsc.ShapeType != "polygon":
          raise "ShapeError"

      # Get the new field name and validate it.
      fieldname = sys.argv[2]
      fieldname = gp.ValidateFieldName(fieldname, os.path.dirname(input))

      # Make sure shape_length and shape_area fields exist.
      if gp.ListFields(input,"Shape_area").Next() and gp.ListFields(input,"Shape_length").Next():
          # Add the new field and calculate the value.
          gp.AddField(input, fieldname, "double")
          gp.CalculateField(input,fieldname, "[Shape_area] / [Shape_length]")
          raise "FieldError"
except "ShapeError":
    print "Input does not contain polygons"
except "FieldError":
    print "Input does not shape area and length fields"
    print gp.GetMessages(2)	

Please visit the Feedback page to comment or give suggestions on ArcGIS Desktop Help.
Copyright © Environmental Systems Research Institute, Inc.