ModifyObjectAttributes not triggering?

I am sure I am missing something very basic, but for some reason I am not seeing the ModifyObjectAttributes event firing when I make changes to objects. I am registering my event handler at the same time as several others (all of which are working), but this one for whatever reason doesn’t get triggered…I am trying to get it to work when I change user strings, but I can’t even get it to fire when I change standard attributes, like layer, etc. I am registering it thus:

RhinoDoc.ModifyObjectAttributes += OnModifyObjectAttributes;

Handling it thus:
void OnModifyObjectAttributes(object sender, RhinoModifyObjectAttributesEventArgs e)
{
// do anything
}

And unregistering thus:
RhinoDoc.ModifyObjectAttributes -= OnModifyObjectAttributes;

Any tips as to what I am doing wrong?

thanks in advance

Hi Dave,

Object modification events seem to work in this sample:

https://github.com/dalefugier/SampleCsEventWatcher

Does this help?

– Dale

Hi Dale-

Thanks for getting back to me. So I had used that repo for my basis in setting up event listeners, and now have also built it for testing. When I change layer, object color, or any other property accessible through the properties window, it triggers the event. However, if I add or change a user string with my plug-in, it doesn’t. I’ve tested it against changing user strings in both the object attributes and the geometry as well. Any ideas as to how I could raise an event when I modify user strings?

best,

Dave

Hi Dave,

If you want a RhinoDoc.ModifyObjectAttributes event triggered when setting object attribute user strings, then set the user strings using a function similar to this:

public static bool SetObjectAttributeUserString(RhinoObject obj, string key, string value)
{
  var rc = false;
  if (null != obj && null != obj.Document)
  {
    var attributes = obj.Attributes;
    if (attributes.SetUserString(key, value))
      rc = obj.Document.Objects.ModifyAttributes(obj, attributes, true);
  }
  return rc;
}

– Dale

Ah, good to know. Thanks for the help!

Hi @dale. Similar issue I am having… The example you showed Dave makes a lot of sense. Was hoping RhinoDoc.ModifyObjectAttribtues would fire when you pick an object and change it’s layer… Because aren’t you technically changing the object attributes by doing this? Given that this isn’t the case, is there another event that fires when one does this?

Thanks in advance,
Marco

Hi @marcotjuliani,

I am unable to repeat what you describe. If I pick an object and change it’s layer using Rhino’s UI, a ModifyObjectAttributes. I’m just using the SampleCsEventWatcher sample to test.

– Dale

Hi @dale,

Yeah same. For now I am relying on a chain of commands to fire to accomplish a similar result…
M

excuse me ,i want to know how to write this method in ghpython?

Hi @Theo2,

As this is an old post, perhaps you can explain in detail what you are trying to do and why?

– Dale

A post was split to a new topic: Import the geometry by layer from Rhino to Grasshopper