TypeErrorException shows up on GhPython but not python shell

I am using a library called py_openshowvar to communicate with a Kuka robot arm from grasshopper. Everything works fine if I run the program from a command line python shell. However, when I run the same thing from GhPython, I get the following TypeErrorException. Not sure why I get the exceptions with GhPython but not when I run it outside the GH environment. The program still connects to the server and retrieves/sends the info I need, but i want to make sure and address this exception. Below is a screenshot, let me know if anyone needs to see more of the code to help me out.

Thanks!

Hi @Nkal

the interpreter behind GhPython add-on and the _EditRhinoScript command is the same. Really really the same. It’s even only loaded once. Therefore, we should safely assume that, given the same input, it would do the same.

We can then ask ourselves the next question, which would be: why are we getting a different error here? This might be due to be calling a function in py_openshowvar.py on line 57 with some different arguments.

Why are the arguments different? I am not sure. It seems that the threading model is also non-standard for GhPython. It seems that something is calling back into the component, or I might need more info to understand exactly what is going on. In general, you cannot update the GH definition from a background or a listener thread. This should only happen from the UI thread.

Giulio

–
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Giulio,

Thanks for the quick reply. When I said python shell I did not mean _EditRhinoScript, but python running on windows command prompt.

Here is a link to the library itself: https://github.com/linuxsand/py_openshowvar

I am thinking the problem is in how the library is using print(), because when I read and write the commands do go to the server, but I do not get the expected feedback on my GhPython component’s output.

Hi @nkal

If you are using Print() from a call that originates from an external thread, it won’t result in any visible output. This is because there is no Grasshopper solution running, so nothing will do the work to collect the results, assign them to the descending components, showing them, etc.

I can only speculate what is happening, do not really know how to help. A possible way to quickly rest if something like this is happening would be, rather than print()ing in Grasshopper, trying to Write to the RhinoApp() commandline:

Rhino.RhinoApp.WriteLine(text)

If you get your code working like that, there are then chances to have it working also in GhPython. You’d have to write the code that “waits” for the external response, and then, only then, finishes computing the component itself.

However, it might also be that this is due to the usage to IronPython rather than CPython. How are you testing this in the “Python shell”?

Giulio,

The problem ended up being that I was receiving encoded data with python, and not properly decoding it inside of the GhPython component (the method worked when i ran the script in a windows command prompt with “python myscript.py”, because an external thread was doing the decoding).

I decided to re-write the software in C# as a custom component, and things are much more stable now.

1 Like