Get object GUID in grasshopper Python component

Hello,

I am trying to reference a piece of geometry, eg a BREP, into Grasshopper from Rhino, then plug this into a Python component and find out what its GUID is. Im using RhinoCommon not rhinoscriptsyntax.

The reason that (i think) I need the GUID is so that I can look at and change attributes and user data attached to the referenced geometry. I know how to do this with geometry I have created in grasshopper and baked (because then I have the GUID), but im stuck when referencing something that was created in Rhino, or that I imported to rhino from another software.

I wonder if someone can help. This must be a really basic question but I have been trying for a long time to find the answer (looking through the rhino common API, reading forum posts, trying all sorts of things that aren’t working), so I guessed its time to post a question here. I think/hope it will either be a simple answer, or I am misunderstanding the basic way this works!

Any help or advice appreciated

Grasshopper will cast referenced Geometry via the guid parameter into the guid of the referenced rhino-Object

are you using rhino 7 or 8 ?

setting type hint of the scripting component to guid also will do the thing.

1 Like

This might help:

1 Like

Hi Tom

Thank you very much for the advice!
I am using Rhino 8

As a follow up question, I can now find the Rhino object with the ID, either by using Rhino.RhinoDoc.ActiveDoc , which gives a type Rhino.DocObjects…
or by using scriptcontext.doc… , which gives a type ‘RhinoCodePlatform.Rhino3D.GH1.Legacy.ProxyRhinoObject’

The first approach, which finds a DocObject, is what I need to adjust the attributes but im wary of the warning in the API documentation against using ‘ActiveDoc’
As far as I can tell though, to adjust the attributes in the way i would like to, i do have to use ActiveDoc, or would there be a better way??

Hopefully this makes sense!

This really depends “where you are”. But in a GH definition, you should be given the active document.

// Grasshopper Script Instance
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;

using Rhino;
using Rhino.Geometry;

using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;

public class Script_Instance : GH_ScriptInstance
{
  /* 
    Members:
      RhinoDoc RhinoDocument
      GH_Document GrasshopperDocument
      IGH_Component Component
      int Iteration

    Methods (Virtual & overridable):
      Print(string text)
      Print(string format, params object[] args)
      Reflect(object obj)
      Reflect(object obj, string method_name)
  */
  
  private void RunScript(object x, object y, ref object a)
  {
    a = RhinoDocument.RuntimeSerialNumber;
  }
}

– Dale