A question on RhinoObject.MeshObjects(with 5 attrbs)

Hi, i’m using this method to create matching mesh pairs for my NURBS. The way i do that is that i assume that the input sequence of the RhinoObjects for the function is always in pair with the output sequence of the ObjectAttributes. So after creation, i just loop through my initial ObjectEnumeration and use the same index to set UserString(the ID of the original object) on the ObjectAttributes. This way it has a reference back to the original object.

Am i right to assume it’s always gonna work, or is there any other way to get the original object’s reference after the mashing is done?

Some Code:

                Mesh[] meshes;
                ObjectAttributes[] objectAttribs;
                var simpleDialog = false;
                var meshParams = MeshingParameters.Coarse;
                var result = RhinoObject.MeshObjects(rhinoObjects, ref meshParams, ref simpleDialog, out meshes, out objectAttribs);

                if (result == Result.Success)
                {
                    foreach (var objectWithIndex in rhinoObjects.Select((value, index) => new { Index = index, NurbsObject = value }))
                    {
                        //Adding Nurbs pair to the new Mesh through ObjectAttribute
                        objectAttribs[objectWithIndex.Index].UserDictionary.Set(StringConstants._NURBSLinkName, objectWithIndex.NurbsObject.Id.ToString());
                        //Setting layer on new ObjectAttribute
                        objectAttribs[objectWithIndex.Index].LayerIndex = doc.Layers.CurrentLayerIndex;

                        //Adding the mesh to the Model
                        doc.Objects.AddMesh(meshes[objectWithIndex.Index], objectAttribs[objectWithIndex.Index]);
                    }

                    doc.Views.Redraw();
                }
                else
                {
                    retVal = "The meshing failed.";
                }

Hi @gabor.konstanzer,

For each mesh added to the appended to meshes, there will also be the originating object’s attributes appended to objectAttribs.

Does this help?

– Dale

Hi @dale, that one i know. My question is that both the meshes, the objectAttribs and the original rhinoObjects are an array/List. My question is if there is any way to know for sure, which objectAttribute belongs to which Mesh? My current method is that i assume that the sequence of meshes in the meshes array matches with the sequence of the original rhinoObjects list and the corresponding objectAttributes array.

It doesn’t feel like the most robust solution, but in practise it works, that’s why i’m asking if it there is any other way or is it intended this way?

Hi @gabor.konstanzer,

Well it is. The function you’re calling splits the results into two pieces: the geometry and the originating object’s attributes, for convenience. So you are assured that meshes[n] will always match that of rhinoObjects[n].

– Dale

Awesome, thank you!