Grasshopper

algorithmic modeling for Rhino

Hi, I want to distinguish the object added, transformed or deleted in Rhino with C#script at GH. 

I want the script to:

1.detective objects added/transformed/deleted event;

2.send back the guid of those objects

So, I try the following script to get the object deleted:

private void RunScript(ref object D, ref object E)
{
Rhino.RhinoDoc.DeleteRhinoObject += EventDel;
D = Del_Times;
E = Del_guid;

}

// <Custom additional code>
int Del_Times = 0;
Guid Del_guid = new Guid();
private void EventDel(object sender, Rhino.DocObjects.RhinoObjectEventArgs dd){
Del_Times++;
Del_guid = dd.ObjectId;
Component.ExpireSolution(true);
}

But Del_guid still get the object be copyed, is it right to use RhinoObjectEventArgs? In RhinoCommonSDK, RhinoObjectEventArgs/RhinoObjectSelectionEventArgs/RhinoReplaceObjectEventArgs lack introduction.

Thank you very much!

 

Views: 297

Replies to This Discussion

I'm a bit fuzzy on what exactly the goal and what exactly the problem is. But there are two observations (probably not relevant to the discussion though).

Firstly you should make sure that you do not handle the event more than once. Either put a class level bool on your script and only add the event handler if that bool is false (then set the bool to true), or remove the handler before adding it.

Secondly I wouldn't use ExpireSolution(true) directly from within the event handler. Instead, you should schedule a solution when you want an update, and expire the component (using ExpireSolution(false)) from within the callback.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service