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.
-
According to ESRI help.arcgis.com/EN/arcgisdesktop/10.0/help/index.html#//… this issue isn't resolved yetuser– user2012年05月30日 12:22:34 +00:00Commented May 30, 2012 at 12:22
-
@user, that just means it's a generic error. Right?Dave– Dave2012年07月09日 23:34:44 +00:00Commented Jul 9, 2012 at 23:34
2 Answers 2
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 definedBBG_GIS– BBG_GIS2011年05月16日 12:28:37 +00:00Commented May 16, 2011 at 12:28
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 featureClassBBG_GIS– BBG_GIS2011年05月16日 10:12:54 +00:00Commented May 16, 2011 at 10:12
-
What is the output from the print statement though? What string do you get in the console?Rob Clark– Rob Clark2011年05月16日 10:18:34 +00:00Commented May 16, 2011 at 10:18
-
when i use 'print featureclass' i see nothing but when i print the featureclass word i see ' ' characters .BBG_GIS– BBG_GIS2011年05月16日 10:28:13 +00:00Commented May 16, 2011 at 10:28
-
1Sounds 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– Rob Clark2011年05月16日 10:33:29 +00:00Commented May 16, 2011 at 10:33
-
1No - 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– Rob Clark2011年05月16日 11:06:42 +00:00Commented May 16, 2011 at 11:06