Select to view content in your preferred language

Python tool works in PyCharm and Terminal, but not in ArcMap

2813
1
Jump to solution
02-12-2013 02:18 AM
ØyvindIdland
Deactivated User
I have a Python tool that runs fine when executed from PyCharm and DOS-terminals, but fails when I execute it from ArcMap 10, SP5.

Stripped down version of the code looks like this:

try:     toolbox_file = os.path.join(arcpy.gp.getMyToolboxesPath(), "MyTools.tbx")     arcpy.ImportToolbox(toolbox_file, "SomeTools")     arcpy.SomeTools.IRAPToESRIVector(.........) except Exception, e:     arcpy.AddMessage("Trying to get some sensible error messages: " + e.message)     msg = arcpy.GetMessages(2)     arcpy.AddError("messages: " + msg)


The output looks like this, with some chinese garble:

Start Time: Tue Feb 12 12:46:07 2013
Running script ToESRIVectorScript...
Importing toolbox: C:\Users\path\to\MyTools.tbx
Processing C:\Users\myself\testdata\p.2.16\File1.irp
Trying to get some sensible error messages: Object: Tool or environment <?????????????????????????????????> not found
messages:
Completed script ToESRIVectorScript...
Failed to execute (ToESRIVectorScript).
Failed at Tue Feb 12 12:46:09 2013 (Elapsed Time: 2,00 seconds)


As you can see, arcpy.GetMessages(2) returns nothing at all, while the exception states that something chinese is not found.

This resembles corrupted memory... anybody had similar issues ?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ØyvindIdland
Deactivated User
Ok, found the issue. First I wrote some code to list available tools in my toolbox:

    toolbox_file = 'C:\Users\path\to\MyTools.tbx'     arcpy.AddMessage('Importing toolbox: ' + toolbox_file)     tbx = arcpy.ImportToolbox(toolbox_file)     if tbx is None:         arcpy.AddError("Toolbox is null")     else:         arcpy.AddMessage("debug: listing tools")         tools = arcpy.ListTools("*MyGISTools*")         arcpy.AddMessage("Number of tools found: %i" % len(tools))         for tool in tools:             arcpy.AddMessage(arcpy.Usage(tool))


Again: when running this in a terminal window (DOS/CMD), or in my IDE (PyCharm), I get a list of all the tools (13 total)

But, when running this in ArcMap, I got a bunch of these:

Method ToESRIRasterScript_MyGisTools not found. Choices: Method ToESRIRasterScript_MyGisTools not unique, please use ToolboxName_ToolName.
Method ToIRAPVectorScript_MyGisTools not found. Choices: Method ToIRAPVectorScript_MyGisTools not unique, please use ToolboxName_ToolName.
Method ToESRIVectorScript_MyGisTools not found. Choices: Method ToESRIVectorScript_MyGisTools not unique, please use ToolboxName_ToolName.
....
....


Which seems to point to something being duplicated. I removed the toolbox from ArcToolbox.
Then, when executing it again from the Catalog window, everything worked just fine.

The chinese random garble must be a bug.

View solution in original post

0 Kudos
1 Reply
ØyvindIdland
Deactivated User
Ok, found the issue. First I wrote some code to list available tools in my toolbox:

    toolbox_file = 'C:\Users\path\to\MyTools.tbx'     arcpy.AddMessage('Importing toolbox: ' + toolbox_file)     tbx = arcpy.ImportToolbox(toolbox_file)     if tbx is None:         arcpy.AddError("Toolbox is null")     else:         arcpy.AddMessage("debug: listing tools")         tools = arcpy.ListTools("*MyGISTools*")         arcpy.AddMessage("Number of tools found: %i" % len(tools))         for tool in tools:             arcpy.AddMessage(arcpy.Usage(tool))


Again: when running this in a terminal window (DOS/CMD), or in my IDE (PyCharm), I get a list of all the tools (13 total)

But, when running this in ArcMap, I got a bunch of these:

Method ToESRIRasterScript_MyGisTools not found. Choices: Method ToESRIRasterScript_MyGisTools not unique, please use ToolboxName_ToolName.
Method ToIRAPVectorScript_MyGisTools not found. Choices: Method ToIRAPVectorScript_MyGisTools not unique, please use ToolboxName_ToolName.
Method ToESRIVectorScript_MyGisTools not found. Choices: Method ToESRIVectorScript_MyGisTools not unique, please use ToolboxName_ToolName.
....
....


Which seems to point to something being duplicated. I removed the toolbox from ArcToolbox.
Then, when executing it again from the Catalog window, everything worked just fine.

The chinese random garble must be a bug.
0 Kudos