Event when modify Archivable dictionaries

Hi all! Thanks for your help!
My Rhino plugin is reading and displaying the info contained in an archivable dictionary in rhino objects.
I’m looking for a way to auto-refresh this info when this archivable dictionary is modified.
Is there an event watcher I could use to check it?
Best!

Hi @p.cortes.nieves,

Rhino has several event watchers that you can subscribe to so you know when your object has changed. RhinoDoc.ReplaceRhinoObject and RhinoDoc.ModifyObjectAttributes come to mind. Have you tried using these?

– Dale

Hi @dale ,

Thanks again for your support.

Exactly, I’ve tested both of them. I downloaded your sample project EventWatchers and I check all the events within in. The problem appears when I change internal user information through a grasshopper plugin: I don’t modify any geometry, so RhinoDoc.ReplaceRhinoObject does not trigger.
I thought RhinoDoc.ModifyObjectAttributes was going to sòlve it, but it did not. I’m changing information that I store in UserDictionary, so that is the only feature I modify in my object.

Any ideas?

Can you provide some sample code that isn’t working for you?

– Dale

Hi @dale ,

I’ve using SampleCsEventWatcher to test the behaviour. I’ve simplyfied the code by doing:

    public void Enable(bool enable)
    {
      if (enable != IsEnabled)
      {
        if (enable)  RhinoDoc.ModifyObjectAttributes += OnModifyObjectAttributes;
        else         RhinoDoc.ModifyObjectAttributes -= OnModifyObjectAttributes;
      }
      IsEnabled = enable;
    }


    public static void OnModifyObjectAttributes(object sender, Rhino.DocObjects.RhinoModifyObjectAttributesEventArgs e)
    {
      RhinoApp.WriteLine("------> Object modified!");
    }

I attached all you need to reproduce my current situation (Rhino file, Grasshopper file, UIM plugin). The plugin generates info that is stored in the ArchivableDictionary’s property, so when we change any panel from Grasshopper with related data, the event should trigger. As a simple example, we can change the panel for setting the labels:

This change should thigger the event, but it don’t. After selecting and deselecting any object in the RhinoDoc, as if it needed to recover the focus, the event triggers.

I hope I have explained myself clearly.

Thanks again,

PC

Hi @p.cortes.nieves,

The GH file and plug-in are missing. Can you provide these, or just a snippet of code that shows how you are modifying the dictionary?

Thanks,

– Dale

@dale Is there any way to send you the files privately?

Sure, just click on my avatar and click the Message button.

@dale I’ve just sent you a private message

Hi @p.cortes.nieves,

Modify object attributes like this:

attributes = rh_object.Attributes.Duplicate()
attributes.UserDictionary.Set('Test', 'Hello Rhino!')
sc.doc.Objects.ModifyAttributes(rh_object, attributes, False)

For example:

import Rhino
import scriptcontext as sc

def _on_modify_object_attributes(sender, e):
    print('_on_modify_object_attributes')

def test_modify_object_attributes():
    filter = Rhino.DocObjects.ObjectType.Curve
    rc, objref = Rhino.Input.RhinoGet.GetOneObject('Select curve', False, filter)
    if not objref or rc != Rhino.Commands.Result.Success: 
        return
    
    rh_object = objref.Object()
    if not rh_object:
        return
    
    Rhino.RhinoDoc.ModifyObjectAttributes += _on_modify_object_attributes
    
    attributes = rh_object.Attributes.Duplicate()
    attributes.UserDictionary.Set('Test', 'Hello Rhino!')
    sc.doc.Objects.ModifyAttributes(rh_object, attributes, False)
    
    Rhino.RhinoDoc.ModifyObjectAttributes -= _on_modify_object_attributes

if __name__ == "__main__":
    test_modify_object_attributes()

– Dale