Get user datas on delete items

rhinocommon

#1

Hi,
I am looking for the user Datas when we delete an Item.
To be more precise I have a list of list of differerent object who all recive "ObjectDatas"
List<List> myList;

ObjectDatas can be a UserData too. So it is useful because when reading the UserData from the selected object I now at which row in the List of List I have to look to find him.

I cannot give too much information on this thing and why. The only thing is that when deleting the objects, in the Events generated I need to get the User Data of this object-> but Rhino always said null reference ? Why?
example :

   private void RhinoDoc_DeleteRhinoObject(object sender, Rhino.DocObjects.RhinoObjectEventArgs e)
        {           
           
            ObjRef obj_ref = new ObjRef(e.ObjectId);   -----------> This works
           var ud = obj_ref.Geometry().UserData.Find(typeof(ObjectDatas)) as ObjectDatas; //something give a NullReferenceException  Why ?????

(Dale Fugier) #2

Why are you trying to ‘find’ the user data of deleted objects?


#3

Hello Dale, because I have a controller behind it and It needs to get the information contained into the User Data’s


(Dale Fugier) #4

Hi Markus,

Perhaps a better approach is to not store the data on the object but rather on some data structure in the plug-in. Then when the object is deleted, you can just ‘tag’ the record as deleted. And the the object is undeleted, you can tag the record as undeleted (too).

That said, this works with the SampleCsUserData RhinoCommon sample project:

private void OnDeleteRhinoObject(object sender, Rhino.DocObjects.RhinoObjectEventArgs e)
{
  if (null != e.TheObject)
  {
    var ud = e.TheObject.Attributes.UserData.Find(typeof(SampleCsUserDataObject)) as SampleCsUserDataObject;
    if (null != ud)
    {
      // TODO...
    }
  }
}