ERROR 000732: Trying to copy shapefile into geodatabase

390
1
01-04-2011 10:59 AM
JeremyDiFilippo
New Contributor
I am very new to writing scripts in Python.  I am trying to follow an example in a tutorial that I'm reading that copies shapefiles from a folder into a geodatabase.  Here is what I have at the moment:

#Import COM dispatch and sys
from win32com.client import Dispatch
import sys

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

#Set the input workspace
GP.Workspace = "E:/gis_py_ex/shapefiles"
try:
   
    #Get a list of the featureclasses
    fcs = GP.ListFeatureClasses("*")

    #Reset the enumeration to make sure the first object is returned
    fcs.reset()

    #Get the first feature class name
    fc = fcs.next()
 
    while fc:
        #Copy the features from the workspace to a geodatabase
        GP.Workspace = "E:/gis_py_ex/results/Testing.gdb"
        outfc = GP.ValidateTableName(fc)
        GP.CopyFeatures_management(fc, outfc)
        #Get the next feature class name
        fc = fcs.next()

except:
    GP.AddMessage(GP.GetMessages(2))
    print GP.GetMessages(2)

Every time I run it I get "Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset Buffer_of_Parcels.shp does not exist or is not supported
Failed to execute (CopyFeatures)."

The shapefile does exist and I checked the path names a hundred times already and everything seems to be correct and in the correct format.  I've been trying to debug this script for about 3 hours now and am making no progress.  Also, does anyone know of a good book that takes you through step-by-step and actually teaches you how to write geoprocessing scripts.  The one I'm using right now is very inconsistent and so far every example I've tried does not seem to work the way it's written in the tutorial.

Any help will be greatly appreciated.  Thank you in advance.
Tags (2)
0 Kudos
1 Reply
JeremyDiFilippo
New Contributor
I was able to attack this issue with a clear mind this morning and found a solution.  I realized that there was no output workspace defined.  Here is my new code:

#Import COM dispatch and sys
import win32com.client, sys, os

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

#Set the input workspace
GP.Workspace = "E:/gis_py_ex/shapefiles"

#Set the output workspace
outWorkspace = "E:/gis_py_ex/results/Testing.mdb"

try:
   
    #Get a list of the featureclasses
    fcs = GP.ListFeatureClasses("*")

    #Reset the enumeration to make sure the first object is returned
    fcs.reset()

    #Get the first feature class name
    fc = fcs.next()
 
    while fc:
        #Copy the features from the workspace to a geodatabase
        outfc = GP.ValidateTableName(fc)
        outFeatureClass = outWorkspace + "/" + outfc
        GP.CopyFeatures_management(fc, outFeatureClass)
        #Get the next feature class name
        fc = fcs.next()

except:
    GP.AddMessage(GP.GetMessages(2))
    print GP.GetMessages(2)

As I said in my first post, the book/tutorial that I'm using seems to be full of mistakes.  This is the second example that I tried and both times I had to modify the code to get it to work.  Hopefully this might help anyone else that might be getting the same error.
0 Kudos