Options for Getting ID of Object that owns Custom.UserData

Hello Forum,

I am currently having a dilemma on the “Correct” way of setting a link between my “Custom.UserData” and the ID of the Geometry it is actually attached to.

What I currently do, is just store a copy of this ID inside of the Custom.UserData, but I want to think that there are better ways to get this linked Geometry’s Guid.

Sorry for the inconvenience, but I can’t upload the code, but I believe the post is clear as it is. If not, I’ll be glad to elaborate.

Thanks for your responses in advance!

Hi @Frusciante,

GeometryBase does not have an ID. The owning RhinoObject has an ID. This this was you’re trying to use?

Perhaps more information on what you are trying to do and why would be helpful?

Thanks,

– Dale

1 Like

Hi @dale,

Thanks for your interest! I am currently developing a plugin, that stores UserData inside a Curve, like the following:

private static void AttachUserData(Guid guid, RhinoDoc doc)
{
    // Get Rhino Object
    RhinoObject rhObj = doc.Objects.Find(guid);

    // Find user data attached to the geometry (it is important to remember that UD is attatched to geometry) for my custom type "EjeUserData"
    var userData = rhObj.Geometry.UserData.Find(typeof(Eje2D_UserData)) as Eje2D_UserData;

    // If user data of my custom type is NOT attached to the geometry
    if (userData == null)
    {
        userData = new Eje2D_UserData();
        rhObj.Geometry.UserData.Add(userData);
    }

    else RhinoApp.WriteLine($"Selected geometry is already set as {userData}");
}

Imagine I have a Display Method that updates based on two general events:

  1. Changes to the Rhino Geometry
  2. Changes in UserData

To keep track of individual objects to change/delete/add, I stored the display data in a Dictionary which has a Key that references a Guid, to keep track of where to update data, based off events.

So, changes to Rhino Geometry, can pass the Guid of the modified object natively, but changes to userData are trigerred withing the UserData class, so they don’t have a direct link to this Guid.

What I did, is to create a new field for the UserData, that stores the Guid on Creation, but there are flaws to this approach, so I wanted to know:

If an instance of my Custom.UserData is stored inside a Geometry, is there another method to retrieve the id of this geometry to which my Custom.UserData is attatched?

Hi @Frusciante,

I’m not tracking here. How is this data being changed, specifically?

– Dale

1 Like

Let me try to elaborate @dale

Something like the following code is what I have for every field:

public void SetFieldA(Guid id, RhinoDoc doc, int newInteger) 
{
    // Store old Index
    int oldInteger = this.GetFieldA();

    // Update Index
    this.FieldA = newInteger;

    // Raise event
    OnFieldAChanged?.Invoke(this, new EventArgs());

    // Give feedback in console
    RhinoApp.WriteLine($"{oldInteger} → {newInteger}");

    // Reflect changes in the document display
    RhinoDoc.ActiveDoc.Views.Redraw();
}

I think we are side tracking from the main question Dale but let me try to elaborate :slight_smile: .

In here an event is raised, which triggers updates on the display.

To properly update, I need to know the Guid of the Geometry that this CustomData is attached.

Why?

I have them in a Dictionary which has unique Guids as keys. This allows me to only update those objects to which changes were made

It might be that this functionality I seek just does not exist, but I ask because it would create better links between my general logic, I just don’t like the idea of storing the ID as a Field hinting to my Geometry, which in principle the CustomData is already attached to it, which just seems redundant.

Also, there are some minor errors that need to be handled specifically, which would not exist if what I’m looking for really does exist.

Basically, what I’m asking is the following…

If CustomData is attached to a geometry, why or how can I ask the CustomData, to point me to this geometry it is attached to?