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
-
1What happens if you try arcpy.CalculateAreas_stats(r"D:\data.gdb\data", "Area")?MapMan– MapMan2014年12月26日 23:26:57 +00:00Commented 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.Jason Scheirer– Jason Scheirer2014年12月27日 05:05:43 +00:00Commented Dec 27, 2014 at 5:05
-
Registering the dll to the GAC still produces the same error.jsheares– jsheares2014年12月27日 08:24:35 +00:00Commented Dec 27, 2014 at 8:24
-
Trying to alias the toolbox to "stats" has no effect.jsheares– jsheares2014年12月27日 09:07:05 +00:00Commented Dec 27, 2014 at 9:07
1 Answer 1
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")