Hi All, I just migrated from Arc 9.3.1 to Arc 10, and now I'm re-writing my scripts to go along. Something a bit odd, though; in the python console within arc I can get this code to run fine:
searchPath = os.path.abspath(arcpy.GetParameterAsText(0)) #path to search
for root, dirs, files in os.walk(searchPath):
for f in files:
if fnmatch.fnmatch(f, searchParam):
shpType = arcpy.Describe(os.path.join(root, f)).shapeType
if str(shpType) == "Polyline":
print "blah blah"
However, when running from within a model, the python interpreter is getting hung up on shapeType, claiming:DescribeData: Method shapeType does not exist
Any ideas on this? Cheers, MattFull code:
# Import system modules
import sys, string, os, fnmatch, arcpy
# Get variables from the ArcGUI *must setup the tool properly in Arc*
searchPath = os.path.abspath(arcpy.GetParameterAsText(0)) #path to search
searchParam = arcpy.GetParameterAsText(1) #search paramater - wildcards OK
shapefileType = arcpy.GetParameterAsText(2) #shapefile type: Polyline, Polygon, Point, etc.
# Search function
resultList = [] #The list for collecting results with...
resultString = "" #Blank the results from previous searches
outFilesMV = "" #Blank the results from previous searches
for root, dirs, files in os.walk(searchPath):
for f in files:
if fnmatch.fnmatch(f, searchParam):
shpType = arcpy.Describe(os.path.join(root, f)).shapeType
if str(shpType) == shapefileType:
tempString = "'" + os.path.join(root, f) + "'"
resultList.append(tempString)
resultList.append(";")
resultList.pop() #removes last list value (trailing semicolon)
resultString = "\"" + "".join(resultList) + "\"" #Convert list to a single string
outFilesMV = resultString.replace("\\","\\\\")
# set Arc output:
arcpy.SetParameterAsText(3, outFilesMV)