What is the best practice to check for model changes?

Hello!

I am constructing a plugin where we have a UserData defined and these objects should be specific, imagine a brep. If changed, I need to check if the brep is still valid, for example if the user uses the Explode command on it, it does influence some other things in my code, hence i wanne then do some adjustments or fixes or prevent the explode for example, or just remove it from my internal structure.

What is the best way to approach this? I prefereably want to know via an event, the specific object that changed, and maybe how it changed in order to compare it and check the validity based on my standards.

Any ideas?

did you see this sample:

          RhinoDoc.AddRhinoObject += OnAddRhinoObject;
          RhinoDoc.ReplaceRhinoObject += OnReplaceRhinoObject;
          RhinoDoc.DeleteRhinoObject += OnDeleteRhinoObject;
          RhinoDoc.UndeleteRhinoObject += OnUndeleteRhinoObject;
          RhinoDoc.PurgeRhinoObject += OnPurgeRhinoObject;
          RhinoDoc.ModifyObjectAttributes += OnModifyObjectAttributes;
          RhinoDoc.BeforeTransformObjects += OnBeforeTransformObjects;

          RhinoDoc.SelectObjects += OnSelectObjects;
          RhinoDoc.DeselectObjects += OnDeselectObjects;
          RhinoDoc.DeselectAllObjects += OnDeselectAllObjects;

hope above helps - kind regards -tom

1 Like

Hi @Benterich,

Something else worth considering.

https://developer.rhino3d.com/api/rhinocommon/rhino.geometry.geometrybase/datacrc

– Dale

1 Like

Thanks for the great input! I am just finishing up another feature and then i am gonna tackle this! I keep you updated here! :student:

Hey, we have been great at work implementing a system. However we stumpled upon one issue you might be able to help me with.

The system works this way: I have all the event watchers active, and they add all objects to a combined list of editedObjects (if the list does not yet contain them).
Then on RhinoIdle I process these objects, checking if they have any of our plugins UserData, if that is the case, we do some checks.
Now, during one of these processes, for example when I explode a polysurface, this would lead to 6 objects being added to our editedObjects List, each having the same userdata objects from the previous polysurface, which is not a problem, since i can now do a check and see that the resulting surfaces, are not valid for the UserData, which is perfect. However, in order to visually show that these spaces dont have userdata anymore, we want to reset them, since we do based on the metadata, face.PerFaceColor. However, as soon as I adjust the the geometry (for example via PerFaceColor = empty), and i undo the explode, it causes a duplication: the surfaces persist, and the polysurface is being readded as it was before. Why are the Surface not being removed?

During the OnRhinoIdle, Event Watchers are disabled.

Am i missing something?

  • Best Ben

This is the coloring code

        public static void ResetObjectColors(RhinoObject rhObj)
        {
            var doc = RhinoDoc.ActiveDoc;

            if (rhObj == null) return;
            var brep = rhObj.Geometry as Brep;
            if (brep == null) return;

            foreach (var face in brep.Faces)
            {
                face.PerFaceColor = System.Drawing.Color.Empty;
            }

            rhObj.Attributes.ColorSource = ObjectColorSource.ColorFromLayer;

            rhObj.CommitChanges();
        }

@Tom_P @dale Would love to hear your input! Did I explain it badly, or can I clarify anything?

Best is to send us an example file and code that we can run to duplicate this issue.

2 Likes

I cannot send you the full solution unfortunatly, I will set up an example solution shortly with the issue!