Select to view content in your preferred language

Batch Project and Copy Features - problem converting from 9.3 (arcscripting) to 10

342
1
01-17-2012 06:15 PM
ArielleSimmons
Emerging Contributor
Hi,

I have this following script that I am trying to test out using IDLE 2.6.5. Notably, I've had a very similar script run before using Arc 9.3...

What I'd like to do:

1) Write a script that looks into a directory, creates a list of shapefiles, and from this list batch projects all the shapefiles in the directory into a specific gdb (i.e. always to be named 'input.gdb'...there is one already existing in each directory). Output feature classes will have a specific name.

2) I would like to be able to use the script in model builder and make the directory user defined (i.e. variable folder in the below script) will be sys.argv(1). A little uncertain how to do this..but theoretically makes sense, right?

3) I am fine hard-coding the search pattern with a wildcard..."*.shp"...mostly because I doubt some of my users will know what a wildcard is...

SO far my script looks as thus:
##Convert and reporoject shapefiles from RR_Sierra_Nevada\Forests
## Import modules and create geoprocessor object

import arcpy
import os
import fnmatch
import sys
import string

# Set the workspace. List all of the shapefiles


# input workspace

arcpy.env.workspace = r"D:\RR_Sierra_Nevada"

# returns a list of shapefiles in the specified folder
# that match the specified wildcard search pattern

folder =r"D:\RR_Sierra_Nevada\Forests\Inyo"
pattern = "*.shp"
shpList = []

for path, dirs, files in os.walk(folder):
       for filename in fnmatch.filter(files, pattern):
               shpList.append(os.path.join(path, filename))

arcpy.AddMessage("Shapefiles returned:")
for shp in shpList:
       arcpy.AddMessage(shp)

print shp


The error I keep getting is EITHER a blank return...or there is no such thing as 'import arcpy' (?).

Any thoughts...
Tags (2)
0 Kudos
1 Reply
MathewCoyle
Honored Contributor
No such thing as "import arcpy" is fairly troubling. Try opening IDLE and input help("arcpy"). Should come up with all the information on the module, file location etc. You mentioned previously using 9.3, did you cleanly remove all elements of 9.3 prior to installing 10 on your machine? Python 2.5 as well as Arc 9.3?

Could you post the actual error message you are getting?
0 Kudos