Storing data in pure geometry classes

Hi @piac, this is not as related, but would there be a way to store text strings in Rhino.Geometry.Point structures? From what I can tell I can use methods like SetUserString and GetUserString to store and retrieve the data inside scripts and scripted components, but externally it seems like there’s no way to attach the data to the points themselves.

E.g. Say if I clicked on a point, I could type in a command in the Rhino Viewport and set a key like ‘Label’ that will let me store a value like the string ‘1234’ inside a point. Same goes for Text Tag/Text Tag 3D. When I input it to a custom script component, I can retrieve the value ‘1234’ from that same point using the key ‘Label’. Right now, what I’ve go is that:

import Rhino.Geometry as rg

a = rg.Point
a.SetUserString(‘Label’, ‘1234’)
pritn a.GetUserString (‘Label’) #This gives back 1234.

So the Point component here corresponds to all the points in the Rhino Viewport with text on them. If I added Text Tags to these points using a separate Text Tag component or the SetUserData command, how would I go about retrieving the text?

Basically I’m trying to pass rg.Points with strings attached, and I should be able to retrieve the strings stored inside the points even if I put them in as part of the input to a Geometry Component. Is this possible? If not, then what workarounds do you suggest?

Hi again @Bianchi Bianchi,

(please, may I ask to keep one discussion per thread?)

Going back to your question: if you are hoping to have Grasshopper preserve this data after, say, a “Move”, this will not be possible. You will have to maintain the data “in parallel” by yourself. Grasshopper uses Point3d for points, which is a structure that contains only 3 coordinates: {X, Y, Z}. There is no space allocated for other stuff, so it’s more efficient.

Point derives from GeometryBase so it has more features, but it’s also heavier memory-wise. Grasshopper transforms Points you pass in output parameters to Point3ds. So this data is immediately lost.

It’s not a workaround. This is how Grasshopper works. You just need to keep trees “in parallel” and everything will work.

Hi @Piac, my mistake. I was in a hurry yesterday so I added to the old one instead of making a new thread. Thanks for moving the discussion here.

Thanks for enlightening me on how Grasshopper handles Point structures. I’ll stick to maintaining it in parallel then.