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.

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
  • i don't have any problem with : featureClass = arcpy.GetParameterAsText(0) print featureClass – BBG_GIS May 16 '11 at 10:12
  • What is the output from the print statement though? What string do you get in the console? – Rob Clark May 16 '11 at 10:18
  • when i use 'print featureclass' i see nothing but when i print the featureclass word i see ' ' characters . – BBG_GIS May 16 '11 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? – Rob Clark May 16 '11 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#/… – Rob Clark May 16 '11 at 11:06
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.

  • now thisis my error : Traceback (most recent call last): File "<interactive input>", line 1, in <module> NameError: name 'featureClass' is not defined – BBG_GIS May 16 '11 at 12:28

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.