Detect update/change in input geometry - c#

I have a list of referenced objects in GH that feed into a C# component. (they exist in the document)

Now lets say i move / rotate / edit one of the referenced objects, can my C# component detect that? How?
The idea would be that the processes inside the component at the first execution calculate for all (as it does now anyway), and only updates the modified objects?

To give a real example - I have a ‘Mesh-pipe’ c# component, that stores the meshes it generates, and Outputs them back into GH. Now if i move one of the input curves, i could skip all the calculations, but the one that changed.

How to do that?

1 Like

You have to store the geometry already used in a variable and compare at each new reading parameter.
Making the comparison can be easy or screwed. For example, if you compare two meshes, you can first compare the number of vertices (if different, you know they are different objects), or the number of faces … then the position of the points etc. Sets the order of the comparisons of objects based on performance.
Or type geometry, curve length, volume of the bounding box… any particularity.

This is annoying to program but it works.
If there is a more advanced way I would love also to know it.

EDIT: Here you have an example (in VB):

Thanks for the input - that would be one option.
Although, i just checked, every rhino object has a GetHashCode() method, which changes with every edit, but i am not sure if it is the right method for this

I just tested and the GetHashCode() gives a new result everytime the component is run, no matter whether the geometry change or not.

– at least for mesh object.

reviving this old topic - as i once again face the problem… and found a strange workaround:

haven’t tested it too much, but it looks like if you add userdata it is persistent upstream, as long as the object is not rebuilt - let me explain:

  • lets say a c# component reads in a mesh, modifies some vertices, and outputs it
  • as long as the output is the same object as the input, userstrings are kept
  • the trick is - if you add one it also exists now upstream! - on all nodes the mesh went through before including the current one
  • so you can set/read an string id - if none exists, the mesh is ‘new’ and you set it and run whatever needs to be run once
  • if it exists you can bet its the same mesh as before

I don’t think this helps to identify changes from the document, but at least for stuff generated within grasshopper (as long as it is a class and supports userdata)

Edit: just saw the reply above leads to a simpler solution… anyway - this is maybe still useful
Edit2: the above linked solution only works if it is not the same object - so you need a independent duplicate (duplicateMesh()) for it to work. My workaround rather detects if the same object was overwritten somewhere upstream - so slightly different

For Mesh, you can do this: