Hi there, I'm new to scripting and still struggling to figure out how everything works. When a call the FieldMappings function in the script the following error occurs: <type 'exceptions.AttributeError'>: Object: Tool or environment <s> not found Failed to execute (runAccuracy). I know for a fact it is the at the exact moment when I call the function when the script fails. I'm doing exactly the same than a few examples I found on the internet on setting up FieldMappings for python scripts. The code is provided below: import arcgisscripting, os, sys, string, math, traceback, shutil, subprocess from time import localtime, strftime import arcpy import os from arcpy import env from arcpy.sa import * arcpy = arcgisscripting.create(10.0) arcpy.overwriteoutput = 1 arcpy.CheckOutExtension("Spatial") arcpy.SetProduct("ArcInfo") class GetOutOfLoop( Exception 😞 pass # Version version = 1 # Directories fportion_loc = "C:/Divan/FPortion/FPortion/" points_loc = "C:/Divan/FPortion/Points/" temp_loc = "c:/Divan/FPortion/temp/" export_loc = "C:/Divan/FPortion/Exported/" ws = temp_loc env.workspace = ws # Checks the extension of a given file def checkExtension(fileName, extension): length = len(fileName) # If the string length is less than 3 character, it can't be a .shp or .tif file if length < 3: return -1 else: lowercase = fileName.lower() found = lowercase.find(extension, length - 4, length) if found == -1: return -1 else: return 0 try: # List all files fportionFiles = os.listdir(fportion_loc) pointsFiles = os.listdir(points_loc) # Loops through all the fportion_loc files for fportionfile in fportionFiles: if checkExtension(fportionfile, ".shp") != -1: index = fportionfile.find("_") # Finds the index of the '_' character prefix = fportionfile[:index] # Stores the prefix of the file arcpy.AddMessage("Zone(polygon) shapefile found: " + fportionfile) arcpy.MakeFeatureLayer(fportion_loc + fportionfile, fportionfile + "_ref_fportion") cnt = 0 # Loops through all the dem_loc files for pointsFile in pointsFiles: points_lowercase = string.lower(pointsFile) if checkExtension(points_lowercase, ".shp") != -1: arcpy.AddMessage("Point shapefile found: " + pointsFile) arcpy.MakeFeatureLayer(points_loc + pointsFile, pointsFile + "_tmp") arcpy.AddMessage("Creating fieldmappings...") fieldmappings = arcpy.FieldMappings() # The error occurs when I call this function arcpy.AddMessage(" bla!!!!") #fieldmappings.addTable(fportion_loc + fportionfile) #fieldmappings.addTable(points_loc + pointsFile) #fieldIndex = fieldmappings.findFieldMapIndex("RASTERVALU") #fieldMap = fieldmappings.getFieldMap(fieldIndex) #fieldProperties = fieldmap.outputField #field.name = "mean_elev" #field.aliasName = "mean_elev" #fieldMap.outputField = field #fieldMap.mergeRule = "mean" #fieldmappings.replaceFieldMap(fieldIndex, fieldMap) #arcpy.AddMessage("Executing spatial join...") #arcpy.SpatialJoin_analysis(fportionfile + "_ref_fportion", pointsFile + "_tmp", export_loc + prefix + "_done.shp", "JOIN_ONE_TO_MANY", "KEEP_ALL", fieldmappings, "CONTAINS") except GetOutOfLoop: pass The code that has been commented out to determine where the error occurs. Thanks in advance
... View more