Show Navigation | Hide Navigation
You are here:
Geoprocessing > Automating your work with scripts > Scripting object: Properties and Methods > Properties and Methods

ValidateFieldName method

Release 9.3
Last modified January 19, 2010
E-mail This Topic Printable Version Give Us Feedback

Print all topics in : "Properties and Methods"

Related Topics

Note: This topic was updated for 9.3.1.

Takes a string (field name) and a workspace path and returns a valid field name based on name restrictions in the output geodatabase. All invalid characters in the input string will be replaced with an underscore (_). The field name restrictions depend on the specific database used (Structured Query Language [SQL] or Oracle).


object.ValidateFieldName(inputFieldName As String, {Workspace} As String) As String

{} = optional

Part Description
object The instantiated geoprocessing object
inputFieldName The field name to be validated
Workspace Optional. The workspace in which the field can be found


# Create a new numeric field containing the ratio of polygon area to
#   polygon perimeter. Two arguments, a feature class and field name,
#   are expected.

import arcgisscripting
import os
gp = arcgisscripting.create(9.3)

# 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 len(gp.ListFields(input,"Shape_area")) > 0 and             len(gp.ListFields(input,"Shape_length")) > 0:

            # 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.