Select to view content in your preferred language

FeatureClassToFeatureClass_conversion works in IDLE but not as a tool

2130
4
09-27-2010 06:32 AM
deleted-user-rQoEFM5qzbHE
Deactivated User
I was attempting to export a joined table to a new shapefile. I was successful in doing this through the IDLE debugger. However, when I try to do it as a tool in ArcToolbox, it crashes. I get an error message that says "A locator with this name does not exist".

I am not exactly sure what this error means in the context of exporting one feature class to another.

Thanks.
0 Kudos
4 Replies
RDHarles
Regular Contributor
Without see your script, just guessing, but that error message USUALLY has to do with full paths (or lack thereof) to your input or output shapefile.
0 Kudos
deleted-user-rQoEFM5qzbHE
Deactivated User
But it works if I run it from IDLE, that is what seems confusing. Even though I have set up inputs when running it as a tool, I commented out those sections and still have the paths hard coded in as if I was running it from IDLE.
0 Kudos
RDHarles
Regular Contributor
Every environment (command line, IDLE, PythonWin, Toolbox) you run your script from is a little different (as far as coding goes). I don't run scripts from ArcToolBox, as it only complicates things, in my opinion.  I'm sure if you post your
script, the ArcToolBox experts on the board will take a look.
0 Kudos
deleted-user-rQoEFM5qzbHE
Deactivated User
Alright, here is the code for my script. It is a bit messy at the moment...

# Import system modules
import sys, string, os, arcgisscripting

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

# Load required toolboxes...
gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
try:
    gp.OverWriteOutput = True
except:
    gp.AddMessage("Unable to set the OverWriteOutpu to 1")

# Script arguments...
##inTable = gp.GetParameterAsText(0)
##inFC = gp.GetParameterAsText(1)
##String = gp.GetParameterAsText(2)
##SchoolLevel = gp.GetParameterAsText(3)
##numSchools = gp.GetParameter(4)
##        
###gp.SetParameterAsText(5,"PS_lyr")
##
##SchoolLevel = "[" + SchoolLevel + "]"

inTable = "D:/ORED PROJECTS/GAMS to ArcMap/ES_05_UNROUNDED.csv"
inFC = "D:/ORED PROJECTS/GAMS to ArcMap/ScenarioTemplate_1011.shp"
String = "ES_06"
SchoolLevel = "[ES_0910]"
numSchools = 11

fieldsListFC = gp.ListFields(inFC)
#theFields = gp.ListFields(inFC)

# Process: Add Field...
gp.AddField_management(inFC, String, "TEXT", "", "", "30", "", "NON_NULLABLE", "NON_REQUIRED", "")


descTable = gp.Describe(inTable)
FullTName = descTable.CatalogPath
theTPath = (os.path.split(FullTName)[0])
theTName = (os.path.split(FullTName)[1])

descFC = gp.Describe(inFC)
FullFCName = descFC.CatalogPath
FullFCNameOut = FullFCName.replace(".shp", "_copy.shp")
theFCPath = (os.path.split(FullFCName)[0])
theFCName = (os.path.split(FullFCName)[1])

outFC = theFCName.replace(".shp", "_copy.shp")
gp.TableToDbase_conversion(inTable,theTPath)
outTable = inTable.replace("csv", "dbf")

# Process: Calculate Field...
gp.CalculateField_management(inFC, String, SchoolLevel, "VB", "")
gp.MakeFeatureLayer_management(inFC, "PS_lyr", "#", "#", "#")
gp.AddJoin_management("PS_lyr", "segment", outTable, "SEG", "KEEP_ALL")

gp.FeatureClassToFeatureClass_conversion("PS_lyr", theFCPath, outFC)

def zeros(*shape):
    if len(shape) == 0:
        return 0
    car = shape[0]
    cdr = shape[1:]
    return [zeros(*cdr) for i in range(car)]

# Determine the number of fields in the database after the GAMS
# output has been joined to the Scenario Template shapefile
theJoinFields = gp.ListFields(FullFCNameOut)
theFields = gp.ListFields(inFC)
theTableFields = gp.ListFields(outTable)
lengthFC = len(theFields)
##lengthTable = len(fieldsListTable)
lengthJoin = len(theJoinFields)
fieldsJoin = zeros(lengthJoin,1)

# Create an array to hold the planning segment values for each
# of the schools

Elem = zeros(numSchools,1)

for i in range(0,numSchools):
    Elem = theTableFields[i + 2].name.encode('ASCII')

schools = zeros(numSchools,1)
M = zeros(numSchools,2)

rows = gp.UpdateCursor(outFC)
row = rows.next()

try:
    while row:
        for i in range(0,numSchools):
            schools = row.GetValue(Elem)
            M[1] = schools
            M[0] = Elem

        M.sort(lambda x, y: cmp(x[1], y[1]))
        M.reverse()

        if "SEG" > 0:
            school = M[0][0]
            row.SetValue(String, M[0][0])

        gp.AddMessage("You made it through the if statement")
        rows.UpdateRow(row)
        row = rows.next()

except:
    gp.AddError("Failed to set the value of new scenario field to new school assignment")

for i in range(0,numSchools):
    #gp.deletefield(FullFCNameOut, theFields[lengthFC + 1 + i])
    gp.DeleteField_management(FullFCNameOut, "ES_05_UNRO; ES_05_UN_1")
    
##for i in range(0,numSchools):
##    gp.AddJoin_management("PS_lyr", String, inTable2, "NAME", "KEEP_ALL")
##
##    if "NAME" <> "NULL":
##        gp.CalculateField_management("PS_lyr", String, "NAME", "VB", "")
##
##gp.RemoveJoin(inFC, inTABLE2)
##
##gp.FeatureToPolygon("PS_lyr", inFC, "ATTRIBUTES", "")

del gp


The reason for setting this up as a tool, is that it is for some co-workers. They will be using this many times a year and will have different inputs each time.

Thanks.
0 Kudos