ReplaceRhinoObject event for Group objects

Hi everyone,

I have plugin objects which are grouped for some functionality of plugin. I want to update my object by using ReplaceRhinoObject when user move this object via gumball and Move command. The problem that I encounteer here, I cannot reach guids of subobjects of group. Guids coming like {00000000-0000-0000-0000-000000000000}. How can I handle this problem?

Sample psuedocode;

private void RhinoDoc_ReplaceRhinoObject(object sender, RhinoReplaceObjectEventArgs e)
{
    // I have grouped plugin objects in Rhino
    RhinoObject rhinoObject = e.NewRhinoObject;

    // When I get sub objects in the group, their guids come {00000000-0000-0000-0000-000000000000}
    List<RhinoObject> rhinoObjects2 = rhinoObject.GetSubObjects().ToList();

    // There is a helper method which is working with guid of sub objects.
    UpdatePluginObjectAfterReplacing();

    // Deleting old one
    RhinoDoc.ActiveDoc.Objects.Delete(e.OldRhinoObject.Id, true);
}

Thanks in advance,
-Oğuzhan

Hi @oguzhankoral,

RhinoObject.GetSubObjects, is used to explode a Rhino object into subobjects. The returned objects have not been added to the document, which is why their id’s are Guid.Empty.

That said, what are you trying to do? Please be specific - thanks.

– Dale

I understood the reason, thanks.

What I want to achive;
I have nested plugin objects (grouped in Rhino) which are inherit some features from floor to top. When user change something on the this object via UserInterface, I need to recreate this object to update, of course. But when I move the object and change values from UI, the object updates itself at the old location (It come back old location). So, I need to count in transformations (move, rotate, scale) to protect locations after user changes.

What I tried to achieve
Because of the reasons that I mentioned above, I am updating the objects using with Guid of subobjects. So I have a method which is ReadGeometry in order to take values from geometry to update my plugin object. That’s why I am trying to get Guids from in the event of RhinoDoc_ReplaceRhinoObject ;

List<RhinoObject> rhinoObjects = e.NewRhinoObject.GetSubObjects().ToList();

// empty list to collect guids
List<Guid> guidsOfSubObjects = new List<Guid>();
foreach(RhinoObject item in rhinoObjects)
{
    guidsOfSubObjects.Add(item.Id);
}

// Method for read values that plugin needs to recreate the plugin object after changes or transformations
ReadGeometry(guidsOfSubObjects);

I hope it is clear what I want to achieve.
Thanks
-Oğuzhan

If I understand correctly, you are using RhinoCommon’s Group object?

If you need all the objects that are members of a group, use GroupTable.GroupMembers.

RhinoObject.GetSubObjects , is used to explode a Rhino object into subobjects. For example if you have a Brep object that looked like a box, this method would return it’s 6 surfaces a Rhino objects (e.g. explode).

– Dale

@dale,

The problem here, the event which is ReplaceRhinoObject triggers for every object, it is not considering group object as one object.

Because of the structure of grouped PluginObject, it need to update just one time. When it is replacing for each subplugin object, this calculated properties becoming problematic.

private void RhinoDoc_ReplaceRhinoObject(object sender, RhinoReplaceObjectEventArgs e)
{
    UpdatePluginObjectAfterReplacing();
}

If I use Command.EndCommand with

private void Command_EndCommand(object sender, CommandEventArgs e)
{
    if(e.CommandEnglishName == "Move" || e.CommandEnglishName == "Scale1D")
    {
        UpdateBuildingAfterReplacing();
     }
}

It is working as desired, this event triggers just one time. Because it’s not care about geometry. I wish we have Gumball event like EndCommand.

Briefly

I can not use ReplaceRhinoObject event for grouped object.
Any suggesstion?

-Oğuzhan

Hi @oguzhankoral,

Grouping objects allows selecting multiple objects by picking one of the group components. Object grouping can also be ignored when picking if you press Ctrl+Shift and then click.

Grouped object are modified individually. That is, if you pick a group and move it, each object in the group is transformed individually. I believe this is the undesired behavior you are describing. There isn’t anything I can about this.

Anyway, if you want to use groups to track objects, then have a look at the following example code, as it demonstrates one way of tracking grouped object changes. Note, I have not tested this.

TestOguzhankoralPlugIn.cs (5.0 KB)

– Dale

1 Like

Hi @dale,

It was really good approach to separate with GroupHelper layer. It solved my problem for now.
Thanks.

-Oğuzhan