There is some existing code for calculating shapefile area with
python, as I listed below.

import arcgisscripting
import sys

gp = arcgisscripting.create()

# Set a default workspace
gp.workspace = "d:/MA_resevior"

# An input polygon feature class
inputFC = sys.argv[1]

gp.AddField_management(inputFC, "new_area", "DOUBLE")
gp.CalculateField_management(inputFC, "new_area", "float(!
SHAPE.AREA!)", "PYTHON")


However, python shows error message:

Traceback (most recent call last):
  File "D:\MA_resevior\LU_PL_Exportcoef.py", line 16, in <module>
    inputFC = sys.argv[1]
IndexError: list index out of range

If I change sys.argv[1] to sys.argv[0], and print sys.argv[0], it
shows D:\MA_resevior\LU_PL_Exportcoef.py, which is my python code
file. It shows error message:

Traceback (most recent call last):
  File "D:\MA_resevior\subbasin_LU\LU_PL_Exportcoef.py", line 24, in
<module>
    gp.AddField_management(inputFC, "new_area", "DOUBLE")
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Table: Dataset D:\MA_resevoir\LU_PL_Exportcoef.py
does not exist or is not supported
Failed to execute (AddField).

I'd appreciate any help you might give me.

Jen


Reply via email to