Python rhinoscript AddText() not working


Does anyone know whether there is a work around for this method not working. We I call this method I get this error message

Runtime error (NotSupportedException) This type of object is not supported in Grasshopper, so this python script cannot create it.


as far as I know, the GHPython component doesn’t support the “preview” of a few types of objects, (text and hatches for sure…maybe some others?). @stevebaer or @piac would certainly know better. I believe the C# component does not have this limitation. Some info here:

You can bake the objects, (doesn’t solve your preview issue, but…), you could do something like: (note; I’m not certain if it’s best practice to put the sc.doc stuff in the function).

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino    

def BakeStuff():
    sc.doc = Rhino.RhinoDoc.ActiveDoc
    rs.AddText(x, [0,0,0])
    sc.doc = ghdoc

if Bake:

What do you mean? There is no intrinsic limitation. Free-floating hatches and similar have no preview in general. Grasshopper has no knowledge (does not especially “pass around”) hatches, does not visualize them, does not edit them. They are just like any external type. This is the same in C#. rhinoscriptsyntax functions that target these need to do their work in the Rhino document, but work also from GhPython.

Poor choice of terminology on my part. What I was trying to say was that not all objects “work” the same.

example: (from within a ghpython component)

import rhinoscriptsyntax as rs
a = rs.AddPoint(5,5,5)  # will result in a point being previewed
#if  you then add this...
b = rs.AddText("My Text", a)  # will result in an error

Yes, as long as Grasshopper does not know about TextObjects, we decided to keep them out of it. But this can change in the future.

Please note the C# components have no access to the rhinoscriptsyntax library you mention, so the reference is out of context.

To your sample, you can add:

import scriptcontext as sc
import Rhino
sc.doc = Rhino.RhinoDoc.ActiveDoc

#at the end of the script...
sc.doc = ghdoc

and the sample will work in the Rhino doc.

Good point, my mistake. With that said, am I mistaken about the C# component being able to show previews of hatches/text, (when properly constructed with RhinoCommon, NOT rhinoscriptsyntax), where as the GHPython component does not? I must be conflating things…

Apologies for any misleading/out of context statements, thanks for clarifying!

Can you send a sample definition of what you mean, please?
Here is what I see (nothing): (3.7 KB)

hrmm, I have obvioulsy misunderstood something I thought I read…I thought it was something about the C# component’s inheritance of a display class, (or something close to that…), that the ghpython component did not. I am obviously incorrect and/or grossly misunderstanding. Upon further reading/research, it looks like there is a bit more to this than I simplified. Feel free to delete any of the above posts that are misleading/detracting.

also, ,thank you for all the info. I found this and it seems to describe a much simpler/direct logic.

Don’t worry, this is fine.

The GhPython component was only imperative in V5. Now in V6, there’s the GH_Component mode that directly inherits from the Grasshopper SDK class, and that makes it possible to override some SDK methods. If required. That’s a very advanced and corner-case topic, really. Not geometry-related.

ghpythonlib is a module. That module was also Python-only. It allows to call into Grasshopper components as though they are functions. In V6, that functionality is also available in C# (in the NodeInCode namespace).

Good news, I found another thread where Giulio wrote a class called “TextGoo” which works great and is exactly what I was after.

1 Like