Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a problem executing the code below. The file is not found in split_row_0717.py Please kindly help any modification and thank you.

The error said that

Traceback (most recent call last): File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in main._dict_ File "H:\python_p\python_code\split_row_0717.py", line 46, in gp.SplitByAttribute_Analysis2(fc, fieldName, outWorkspace, fieldName) AttributeError: Object: Tool or environment not found

##Script Name: split rows
##Description: using 
##Created By: Elaine Kuo
##Date: 12/07/2012


#Import standard library modules
import arcgisscripting
import os

#Create the Geoprocessor object
gp = arcgisscripting.create(9.3)


#Set the workspace.
gp.Workspace= "H:/temp/test"


#Set the workspace. List all of the feature classes in the dataset
outWorkspace= "H:/temp"

# Add a toolbox with a model to the geoprocessor and set the workspace
gp.AddToolbox("C:/Program       Files/ArcGIS/ArcToolBox/Toolboxes/AdditionalAnalysis/Additional Analysis - Generic Tools.tbx")


#Get a list of the featureclasses in the input folder
fcs = gp.ListFeatureClasses()

# Loop through every item in the list that was just generated
for fc in fcs:

    # Break out the name, no path or extension, using the describe object.
    desc = gp.describe(fc)
    featureName = desc.name

    # Validate the new feature class name for the output workspace.
    OutFeatureClass = outWorkspace + os.sep + gp.ValidateTableName(fc,outWorkspace)

    #get file name
    fcName, fcExt = os.path.splitext(fc) 

    #build field name
    fieldName = fcName

    #### Execute Script Tool ####
    gp.SplitByAttribute_Analysis2(fc, fieldName, outWorkspace, fieldName)


gp.AddMessage(gp.GetMessages())
print gp.GetMessages()
share|improve this question
    
I guess he could try use a raw string value? (r"C:\\blahblahblah...) –  user9007 Jul 20 '12 at 11:12

1 Answer 1

There might be a problem with your filepath in this line:

# Add a toolbox with a model to the geoprocessor and set the workspace
gp.AddToolbox("C:/Program       Files/ArcGIS/ArcToolBox/Toolboxes/AdditionalAnalysis/Additional Analysis - Generic Tools.tbx")

The spaces look off. I am assuming that SplitByAttribute_Analysis2 is part of this toolbox though. Where possible, it makes things easier if you don't have spaces in your filenames (e.g. Additional Analysis - Generic Tools could be AdditionalAnalysisGenericTools

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.