error in batch feature to point

Discussion created by helenak on May 1, 2012
Latest reply on May 7, 2012 by dlee-esristaff

I have a python code at hand to batch the process of feature to point.

Question 1
In the loop section, it showed that "This object does not support enumeration."
Please kindly point out the error in the code for a beginner.

Question 2
This code did work for a single shapefile but not for multiple ones.
Please kindly use attached shapefile and have a try. (copying it to two or three)
Please also help with the error in the batch code.
Thanks a lot.

##Script Name: Multi centroid
##Description: Get centroid of shapefiles
##Created By: Elaine Kuo
##Date: 29/04/2012

#Import standard library modules
import win32com.client, sys, os

#Create the Geoprocessor object
GP = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")

#Set the input workspace
#GP.workspace = sys.argv[1]
#Set the workspace.
GP.Workspace= "G:/temp_stage_2_dissolve_by_B_NB/test"

#Set the output workspace
#outWorkspace = sys.argv[2]
#Set the workspace. List all of the feature classes in the dataset
outWorkspace= "G:/temp_stage_3_centroid_of_B_NB/Sylviidae_86"

    # Create a list of all the features within the workspace.
    FCs = GP.ListFeatureClasses()


    # Loop through every item in the list that was just generated
    for fc in FCs:

        # Break out the name, no path or extension, using the describe object.
        desc = GP.describe(fc)
        featureName = desc.name

        # Work the magic.
        outFeatureClass = outWorkspace + os.sep + GP.ValidateTableName(featureName, outWorkspace)
        GP.FeaturetoPoint(fc, outFeatureClass)

    print GP.GetMessages(2)