Debug Python Toolbox

3477
9
10-23-2012 07:07 AM
DavidLamb
New Contributor III
I like the idea of Python Toolboxes, but I have to admit implementing them is not very easy.  I'm trying to add a simple toolbox (perhaps simple should be in quotes?) and get a dreaded big red x through the script.  According to the help:

A tool icon that has been replaced with an error icon (Invalid Script) indicates a failure in the tool. To see an explanation of the problem, right-click the toolbox and click Why. This opens a Python Errors dialog box, which provides the error type and line number. This will cover errors in the tool's __init__, getParameterInfo, or isLicensed methods.


Unfortunately, when I do this there is no "Why".  I can check the toolbox for syntax errors but there are none.  How can find out what is wrong with my code?

Also, I tried to search the forums, but no results are returned.  Am I missing the ability to search individual forums such as the python forum, or is that not implemented either?

Thanks for any guidance.

David
Tags (2)
0 Kudos
9 Replies
DanPatterson_Retired
MVP Emeritus
post a screen of your toolbox and a list of the parameters you specified for it.
0 Kudos
DavidLamb
New Contributor III
Thanks for the response.  I figured out what was missing.  But if you have any recommendations for debugging Python Toolboxes, please pass those along.  Is the "Why" option available to you?

Thanks again,
David
0 Kudos
DavidLamb
New Contributor III
FYI, the Why option is available through the ArcCatalog view rather than ArcToolbox.
0 Kudos
JamieKass
Occasional Contributor
I am having the same problem. I get a big red X on my Toolbox, which means I am unable to open it and even view the potential errors within them. However, when I click "Check Syntax" I get "No Syntax Errors". What does this mean? If there are no syntax errors, what is the problem? If there is an error, why doesn't it tell me where it is? As a test, I added an error, and it was returned when I reclicked "Check Syntax". This seems in all respects to be a bug.
0 Kudos
ChrisFox3
Occasional Contributor III
I am having the same problem. I get a big red X on my Toolbox, which means I am unable to open it and even view the potential errors within them. However, when I click "Check Syntax" I get "No Syntax Errors". What does this mean? If there are no syntax errors, what is the problem? If there is an error, why doesn't it tell me where it is? As a test, I added an error, and it was returned when I reclicked "Check Syntax". This seems in all respects to be a bug.


Could you post the toolbox? It does sound like a bug.
0 Kudos
JamieKass
Occasional Contributor
The toolbox is a couple thousand lines long, and calls a couple of other scripts as well, so I think it would be best if I could send it to you.
0 Kudos
JamieKass
Occasional Contributor
So I too finally figured out the problem in my code. In my case, a return that was carelessly indented out of the function. To find this error, as both PyScripter and ArcCatalog failed to notify me (granted I could have debugged, but that would require running all of my code step by step), I found that by compiling my script, I was notified of the errors that escaped detection. So if you too are at a loss as to why your python toolbox is broken, please compile and check what's returned before you pull your hair out. You can force compile your script with the following code:

import py_compile

py_compile.compile("mymodule.py")
0 Kudos
iskahenyo1
New Contributor

Hi, I was using Spatial Analyst Supplemental toolbox few months back on 10.5 and when i upgraded to 10.6, the pyt toolbox now has a red x mark. Checking the syntax, it showed as attachedSpatialAnalystSupplementalTools_pyt toolbox error. I have no python background so need help to debug this. thank you

0 Kudos
DanPatterson_Retired
MVP Emeritus

interesting, your name doesn't match the name on the last line of the error message. is it a multiuser environment?

0 Kudos