About updating RhinoObject in Grasshopper

Hi everyone,
I’m trying to reference object from Rhino to Grasshopper using Guid, but the GH component doesn’t automatically update every time the Rhino object changes. Is there any way to do this? I saw this method in Rhino.RhinoDoc, but not so sure on how to use it. Thanks in advanced. It seems doable to simply add a button or trigger(RH6 timer) to the component, but that is less elegant right?

Hi @Tommy70101 ,
This would be one way to do it. There could be other ways though.

protected override void SolveInstance(IGH_DataAccess DA)
        {
           
            RhinoObject rhinoObject = RhinoDoc.ActiveDoc.Objects.FindId(myReferencedGuid);
            // Here you do something with the rhino object

            RhinoDoc.ActiveDocumentChanged += documentChangedEvent;


            void documentChangedEvent(object sender, DocumentEventArgs e)
            {
                //When ActiveDocumentChanged event is triggered, SolveInstance will run again
                this.ExpireSolution(true);
            }

        }

Hi Darryl,

Sorry for the late reply. Thank you for your reply. I’ve implemented on Visual Studio and build a plugin with the code. I’m not sure if there is anything that I’ve done wrong, but the plugin doesn’t seem to auto-update its output.

Here are a snapshot of the code and one from Rhino viewport. It is for fetching Rhino geometry from Guid.

Is it possible to do some coding that the Grasshopper geometry can be auto-updated after the Rhino geometry is transformed?


Have a nice day,
Tommy

Hi @Tommy70101 ,
sorry I wrote the wrong event there. RhinoDoc.AddRhinoObject is triggered when you transform an object. The event you subscribe to depends on what you are going to do with the object. If you are transforming it, then it would be like this.

 protected override void SolveInstance(IGH_DataAccess DA)
        {
            Guid id = new Guid();
            if (!DA.GetData(0, ref id)) return;

            RhinoObject rObj = RhinoDoc.ActiveDoc.Objects.FindId(id);

            RhinoDoc.AddRhinoObject += ObjectAddedEvent;

            DA.SetData(0,rObj.Geometry);

            void ObjectAddedEvent(object sender, RhinoObjectEventArgs e)
            {
                this.ExpireSolution(true);
            }
        }