3

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

calcAreaTest.py

import arcpy
arcpy.AddToolbox(r"D:\Toolbox.tbx")
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

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Dec 26, 2014 at 22:31
4
  • 1
    What happens if you try arcpy.CalculateAreas_stats(r"D:\data.gdb\data", "Area")? Commented Dec 26, 2014 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. Commented Dec 27, 2014 at 5:05
  • Registering the dll to the GAC still produces the same error. Commented Dec 27, 2014 at 8:24
  • Trying to alias the toolbox to "stats" has no effect. Commented Dec 27, 2014 at 9:07

1 Answer 1

3

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")

or

arcpy.mytbx.CalculateArea(r"D:\data.gdb\data", "Area")
answered Oct 8, 2015 at 2:17

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.