How to achieve the function of "GUID" component in GH with GHpython?

Hello All!
I would like to know how to achieve the function of “GUID” component in GH with GHpython.

Hello - you’ll need

import System.Guid
from System import Guid

then if you have a Guid that is a string that looks like a Guid, you cam make it into a system guid:

id = Guid(string)

Is that what you mean?


Not exactly.
When I select a curve as input into grasshopper, with “print” in GHpython can get the Guid in grasshopper.
But this Guid is different with the guid of the curve in RhinoDoc, which is what I want.
Because With the RhinoDoc’s Guid I can get extra informations like Layer and object Name.
How to avoid use the GH Guid component but use GHpython to get the Guid of the object in RhinoDoc?

Hello - try setting the ‘type hint’ for the ghPython’s incoming ‘x’ as ‘Guid’

Does that get what you need?



1 Like

Yeah!!!That what I want. But there is no GUID type hint in Grasshopper 1.0?


Is there anyway to achieve in GH 1.0? With code ?
Because I need GH1.0 to compile this plugin.

Hi @RetroPost.LT,

sorry, we added this feature to V6 and GH1 (the one that ships with Rhino 6) last July:

In Rhino 5, compilation was not ready yet.

If you really need to use V5, then you could try transforming the Guid to a string (Type Hint: str) and then parse it back from inside the component ( id = Guid(id_txt) ).

You will also have to switch the scriptcontext.doc to RhinoDoc.ActiveDoc.

Hi, @piac
When I add id = Guid(id_txt) in ghpython and type hint as str it got error : name ‘Guid’ is not defined.
Should I add something before Guid(id_txt)?

It seams that GH got a string which content is “Rhino.Geometry.PolylineCurve” but not the Guid in Rhino like “2953f2d0-…” when I set type hint as str.

You need import System Library,System.Guid()

Do you know why I only get “type string” like “Rhino.Geometry.PolylineCurve” but not the guid string after I set type hint as “str”? Can’t get guid by using System.Guid(“Rhino.Geometry.PolylineCurve”).

Hi @RetroPost.LT

sorry, no, you can’t do System.Guid("Rhino.Geometry.PolylineCurve"). A GUID is just a very big number. It is assigned by the Rhino document when an object is added to it, and it will be unique. It’s not possible to just directly recreate the ID from the geometry, as the two are independent ideas.

So, is there any way to input GUID by code? If there is no GUID type hint for ghpython.

As I was mentioning before, the only way it via a string in V5.

But when I set the type hint as string, it seems that the information of GUID didn’t transmit to GHpython even it’s a string type. This string only contains type information: “Rhino.Geometry.PolylineCurve”. And Guid(id_txt) didn’t work eigher.

Hi @RetroPost.LT

this should be sufficient to explain how to work with Rhino document Guids in Rhino 5. (2.3 KB)


Giulio Piacentino
for Robert McNeel & Associates