3

i have a huge problem with an error . when i use getparameterastext and use it for searchcursor , i encounter to an error .for example the below code

import arcpy
featureClass = arcpy.GetParameterAsText(0)
populationField = arcpy.GetParameterAsText(1)
rows = arcpy.SearchCursor(featureClass)

the error is :

Runtime error : ERROR 999999: Error executing function.

the error is different in pythonwin . the error is :

Traceback (most recent call last): File "", line 1, in File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy__init__.py", line 804, in SearchCursor return gp.searchCursor(*args) File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing_base.py", line 357, in searchCursor self._gp.SearchCursor(*gp_fixargs(args))) RuntimeError: ERROR 999999: Error executing function.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked May 16, 2011 at 7:16
2

2 Answers 2

8

When running from pythonwin, check how you are passing the parameters to the script. You can set up a test script to ensure that things will work without having to reenter the parameters each time (as in the example below). GetParameterAsText and sys.argv will enable you to do the same thing. The only difference is the indexing since sys.argv[0] is the running script name.

import sys
import arcpy
try:
 featureClass = sys.argv[1]
 populationField = sys.argv[2]
except:
 featureClass = "c:/temp/x_pnts.shp"
 populationField = "FID"
rows = arcpy.SearchCursor(featureClass)
for row in rows:
 print row.getValue(populationField)

Here is an example of how you would run a script with just command line entries such as the simplified version below:

import sys
import arcpy
featureClass = sys.argv[1]
populationField = sys.argv[2]
rows = arcpy.SearchCursor(featureClass)
for row in rows:
 print row.getValue(populationField)

The entry on the command line needs to be a space delimited list as show in the image

enter image description here

If you are getting error messages, then the file may be in error or the entries are incorrect.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered May 16, 2011 at 12:13
1
  • now thisis my error : Traceback (most recent call last): File "<interactive input>", line 1, in <module> NameError: name 'featureClass' is not defined Commented May 16, 2011 at 12:28
7

I suggest checking what your value is in feature class in the output console. After getting the value type print featureclass

featureClass = arcpy.GetParameterAsText(0)
print featureClass
answered May 16, 2011 at 9:34
6
  • i don't have any problem with : featureClass = arcpy.GetParameterAsText(0) print featureClass Commented May 16, 2011 at 10:12
  • What is the output from the print statement though? What string do you get in the console? Commented May 16, 2011 at 10:18
  • when i use 'print featureclass' i see nothing but when i print the featureclass word i see ' ' characters . Commented May 16, 2011 at 10:28
  • 1
    Sounds like the object passing in from the tool is incorrect. When you created the tool in your toolbox did you set the data type as FeatureClass in the Parameters dialog? Commented May 16, 2011 at 10:33
  • 1
    No - when you set the data type when you add the script to the toolbox. You do this before you're able to run the tool. See this link - refer to step 3 - help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/… Commented May 16, 2011 at 11:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.