ModifyObjectAttributes not triggering?


#1

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


(Dale Fugier) #2

Hi Dave,

Object modification events seem to work in this sample:

https://github.com/dalefugier/SampleCsEventWatcher

Does this help?

– Dale


#3

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


(Dale Fugier) #4

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


#5

Ah, good to know. Thanks for the help!