I have been experimenting with ESRI's CalculateArea custom tool and it works fine running within ArcGIS from a toolbox. Then I wanted to see if I could run it as a standalone script from the commandline like this:

c:\Python27\ArcGIS10.1\python.exe calcAreaTest.py


import arcpy
arcpy.CalculateArea(r"D:\data.gdb\data", "Area")

The following error occurs:

Traceback (most recent call last):
  File "D:\calcAreaTest.py", line 3, in <module>
    arcpy.CalculateArea(r"D:\data.gdb\data", "Area")
  File "D:\Toolbox.tbx", line 25, in CalculateArea
arcgisscripting.ExecuteError: ERROR 000582: Error occurred during execution.

I can paste the same code from calcAreaTest.py into the ArcGIS Python code window and it works. Anybody know how I can get it to work from the commandline?

Here is the link to the source code of the GPCalculateArea tool if anybody is interested at looking it. GPCalculateArea custom tool

  • 1
    What happens if you try arcpy.CalculateAreas_stats(r"D:\data.gdb\data", "Area")? – MapMan Dec 26 '14 at 23:26
  • Register your tool DLL with the GAC. Getting .Net to play nice from Python.exe is a bit of a precise and annoying task. – Jason Scheirer Dec 27 '14 at 5:05
  • Registering the dll to the GAC still produces the same error. – jsheares Dec 27 '14 at 8:24
  • Trying to alias the toolbox to "stats" has no effect. – jsheares Dec 27 '14 at 9:07

In arcpy you need to use ImportToolbox:

import arcpy
arcpy.ImportToolbox(r"D:\Toolbox.tbx", "mytbx")
arcpy.CalculateArea_mytbx(r"D:\data.gdb\data", "Area")


arcpy.mytbx.CalculateArea(r"D:\data.gdb\data", "Area")

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.