1

I am trying to create a table as part of a script tool, and it always fails with error 999999.

The general idea of the script is that it is calculating proportional coverage of things in a series of buffers, and the tables are needed to compile the results.

The code I'm using creates the tables and works fine in PyScripter and also works fine in the Python window within ArcMap, but will not run as a tool and fails at the create tables part.

I'm not sure if part of the problem is that I'm trying to access the path names and files via the GetParamtersAsText function or not. I have tried countless ways of naming the outputs in the CreateTable_management function. I'm not sure what I am missing here (maybe I need output parameters).

Here is my code (the relevant parts of creating the tables):

import arcpy
import os

#set up workspace location 
Working = arcpy.GetParametersAsText(0) #user provided geodatabase location
arcpy.env.workspace = Working
arcpy.env.overwriteOutput = True

#set up link to buffer files.
Buff50_R = arcpy.GetParameterAsText(3) #user provided: let's pretend file is called 'RightBufferfile'
Buff50_L = arcpy.GetParameterAsText(4) #user provided: let's pretend file is called 'LeftBufferfile'

#Loop through and make table based on the name of each of the buffers for each metric of interest 
#When I use PyScripter or the Python window in ArcMap the tables are created in the working
#geodatabase and are named 'InC1RightBufferfile', InC1LeftBufferfile', etc...
fcList =[Buff50_R, Buff50_L] 
for eachFC in fcList:
    NatVeg_Table = "InC1" + eachFC ##Blank file for any natural veg within each buffer
    arcpy.CreateTable_management(Working, NatVeg_Table)
    arcpy.AddField_management(NatVeg_Table, "BID", "TEXT", 12)
    arcpy.AddField_management(NatVeg_Table, "SUM_Per_Cov","DOUBLE", 20, 4)

    NatForest_Table = "InC2" + eachFC ##Blank file for any forest within each buffer scale      
    arcpy.CreateTable_management(Working, NatForest_Table)
    arcpy.AddField_management(NatForest_Table, "BID", "TEXT", 12)
    arcpy.AddField_management(NatForest_Table, "SUM_Per_Cov","DOUBLE", 20, 4)

    HumanDev_Table = "InC3" + eachFC ##Blank file for any Human Disturbance within each buffer scale
    arcpy.CreateTable_management(Working, HumanDev_Table)
    arcpy.AddField_management(HumanDev_Table, "BID", "TEXT", 12)
    arcpy.AddField_management(HumanDev_Table, "Per_Cov","DOUBLE", 20, 4)

I've tried using Delete_management to delete the table ahead of creating the table with no luck, and have tried commenting out the first table, but get then get the same error starting with the NatForest_Table.

Here is the print out from the Results window for extra info: enter image description here

Here are the parameter configurations; the buffer files correspond to parameters 3 and [4], and all the input feature classes are configured the same way.

enter image description here enter image description here

  • 1
    I recommend debugging the script. In the ArcMap Geoprocessing Options, you can define the Script Tool Debugger as Pyscripter. When you run the script tool, right-click the tool, select Debug, then you can step thru the code, see your variables, etc. – klewis Sep 6 '18 at 23:51
  • Beware of white space and invalid characters in table names for your database (things like @#$%). Do you get an error message? Although you have overwriteOutput set to True is it possible the table already exists and is locked? Try in a try/except block if arcpy.Exists(os.path.join(Working,NatVeg_Table)): arcpy.Delete_management(os.path.join(Working,NatVeg_Table)) - if that fails then the table is probably locked. – Michael Stimson Sep 7 '18 at 0:06
  • Hi - thanks for the suggestions - I'll try the debugger and also try deleting the table using the prefunctory "Delete_management". The script runs fine with hard-code values (that is how it was originally set up to run), so pretty sure it's not a logical error, although you can never be too sure. I'll try a few more things and hopefully will report back with some more meaningful information. Thanks again. – S Koenig Sep 7 '18 at 15:52
0

(This answer is based partly on guess-work, as there is not enough information in the question post to know if this is the cause or not.)

Assuming that there are no more instances of arcpy.GetParametersAsText() elsewhere in the script, then it is unusual that it references parameters 0, 3 and 4 without any parameter 1 or 2. Indeed, the script as posted would ignore the second and third paramters of the tool completely (parameters 1 and 2).

If the tool does actually have only 3 parameters, then you should change these lines:

Working = arcpy.GetParametersAsText(0)
Buff50_R = arcpy.GetParameterAsText(3)
Buff50_L = arcpy.GetParameterAsText(4)

to the following:

Working = arcpy.GetParametersAsText(0)
Buff50_R = arcpy.GetParameterAsText(1)
Buff50_L = arcpy.GetParameterAsText(2)

and make sure that your tools parameters are in the same order as the numbering in the script. Ie, parameter 0 in the script should be 1st in the tool, 1 should be 2nd and 2 should be 3rd in the parameters configuration in the tool.

If this is off the mark, then please edit your question post to include a screenshot of your tool's parameter configuration.

  • Thanks for the suggestion - there are the other GetParametersAsText elsewhere - they just weren't relevant to this problem or called to this part of the script. Thanks! – S Koenig Sep 7 '18 at 15:47
  • Thanks - I've added screenshots of the parameter configuration window. One thing I've been curious about, but that I couldn't find any solid answers for in my interwebs digging, is if there needs to be a derived output as part of the parameters for the create table to work? Some sort of "table in waiting" that is activated when the create table function is used? – S Koenig Sep 10 '18 at 16:14
  • No, you do not need to have a derived output parameter in the script for anything within the script to work (including the create table). The output parameter would only be used (eg, by arcpy.SetParameterAsText(n)) if you wanted to pass the result (eg the new table) to another process within your model after the script had completed. – Son of a Beach Sep 10 '18 at 22:28
0

I finally figured my issue out: The original reference was this:

    NatVeg_Table = "InC1" + eachFC  ##Blank file for any natural veg within each buffer
    arcpy.CreateTable_management(Working, NatVeg_Table)

and the problem was the order of the naming AND not referring to the name properly in the Create Table operation. Using arcpy.AddMessage(NatVeg_Table) to see what was being called showed:

InC1E:\Processing\Final_Model_Input_Layers.gdb\SegmentsFinal_R_50

which obviously can't be followed. The fix was this:

    NatVeg_Table = eachFC + "_InC1"  ##Blank file for any natural veg within each buffer scale
    arcpy.CreateTable_management(env.workspace, os.path.basename(NatVeg_Table))

This corrected the order of the name (removed InC1 from the front and placed it at the end of the name), and allowed the table to be created properly within the CreateTable operation by using os.path.basename to remove the path name from the table name.

  • You could have prefixed the name, but you would have has to use os.path functions to do the work: NatVeg_Table = os.path.join(os.path.dirname(eachFC),"InC1_{:s}".format(os.path.basename(eachFC))). String math is bad juju -- use String.format() instead. – Vince Apr 19 at 0:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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