[Solved] How can I raise an error with custom text from gh_python component?

You probably want to raise an exception: https://docs.python.org/2/tutorial/errors.html#raising-exceptions

Thanks @nathanletwory,

any way to suppress the “Traceback:…”?

Not that I know of. I assume you get a good message in the red balloon now?

Yes, that one is exactly what I wanted, thanks

Check out the AddRuntimeMessage() method of the python component (ghenv.Component), which lets you add different colours of warning balloons (note that calling it doesn’t raise an exception itself, so the script continues as usual)



could you give me an example using this in Python?

Try this out:

from Grasshopper.Kernel import GH_RuntimeMessageLevel as RML
ghenv.Component.AddRuntimeMessage(RML.Warning, "oops")


Note that having an actual exception raised at the same time will override the custom warning message.

You can call this method on any component on canvas which is an GH_ActiveObject.

Oh, so my issue was I didn’t try to use it as something.AddRuntimeMessage(args)

My God this API is so difficult to use without proper python examples.


RuntimeMessageExample.gh (3.9 KB)

1 Like

thnx for showing, im really new to coding.

1 Like