Dear All,
Just a quick follow up for those of you who are interested. The batching script
is now working and is attached below.
The intermediate step of saving the xy layer to a folder was unecessary and has
been removed. The 'MakeXYEventLayer' command only creates "in memory" layers
and not .lyr files on disk. Also, the 'FeatureClassToShapefile' command has
been replaced by the 'CopyFeatures' command, since all that
FeatureClassToShapefile does is call CopyFeatures multiple times. CopyFeatures
is faster.
Thanks again to evryone who replied to my second posting.
Regards,
Chris.
#Import standard library modules
import win32com.client, sys, os
#Create the Geoprocessor object
GP = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
import traceback
#Set the input workspace
GP.workspace = "C:/One"
#Set the shapefile output workspace
outputShapefiles = "C:/Shapefiles"
try:
# Load required toolboxes...
GP.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management
Tools.tbx")
GP.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Conversion
Tools.tbx")
#Get a list of dBase files in the input folder
fcs = GP.ListTables("*","dBASE")
#Loop through the list of dBase files
fcs.Reset()
fc = fcs.Next()
while fc:
# Set the outputname for each output to be the same as the input.
outxyLayer = fc.split(".")[0]
#Convert each dBase table in the list into an xyLayer.
GP.MakeXYEventLayer_management(fc, "X", "Y", outxyLayer, "")
print "Made XYEvent layer %s with %i features" % (outxyLayer,
gp.GetCount(outxyLayer))
#Convert each xyLayer into a shapefile
GP.CopyFeatures(outxyLayer, outputShapefiles + "/" + outxyLayer)
#Move to the next fc in the list.
print "FINISHED converting %s TO %s" % (fc, outputShapefiles + "/" +
outxyLayer)
fc = fcs.Next()
except:
traceback.print_exc()
# If an error occurred print the message to the screen
print GP.GetMessages()
This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor