Missing mesh after using Rhino3dmIO

Hi Folks.

I’m trying to do some work on 3dm files from Rhino6 using the Rhino3dmIO sdk and Visual Studio 2017. The first thing I want to do is make a clean copy of the original 3dm, and then work with that.

But when I open the modified file in Rhino, the mesh isn’t shown. In Rhino, all the layers are visible. And even using the ‘Show’ command in Rhino doesn’t show the mesh.

Here’s the code (‘fi’ is a FileInfo object pointing to the original 3dm file):

File3dm rhinofile = File3dm.Read(fi.FullName);

File3dm newfile = new File3dm()
{
    Revision = 6,
};

foreach (Material m in rhinofile.AllMaterials)
{
    newfile.AllMaterials.Add(m);
}

// set up the new Rhino file...
Layer layer0 = new Layer { Name = "Default", Color = System.Drawing.Color.Black };
newfile.AllLayers.Add(layer0);

// add the meshes...
Layer layer1 = new Layer { Name = "Mesh", Color = System.Drawing.Color.Yellow };
newfile.AllLayers.Add(layer1);
IEnumerable<File3dmObject> qMeshes = rhinofile.Objects.Select(q => q).Where(q => q.Geometry.ObjectType == Rhino.DocObjects.ObjectType.Mesh);
int displayorder = 0;

foreach (File3dmObject obj in qMeshes)
{
    if (obj.Geometry is Mesh mesh)
    {
        ObjectAttributes new_attributes = new ObjectAttributes();
        new_attributes = obj.Attributes;
        new_attributes.LayerIndex = 1;
        new_attributes.DisplayOrder = displayorder++;
        newfile.Objects.AddMesh(mesh, new_attributes);
    }
}

When I use the debugger in Visual Studio, I can see that the mesh is there when I explore the ‘newfile’ File3dm object. I tried it with and without the DisplayOrder attribute. The other weird thing is that I did something like this a year or so ago and it worked.

Any ideas?
Thanks!
Don

Hi @don.sayler,

Can you post a sample 3dm file you’re wrestling with? Also, can you provide the version of Rhino3dmIO you are using?

– Dale

Hi Dale.

I’ve asked our designer to generate something non-proprietary that demonstrates the problem.
Rhino3dmIO version is 6.22.20028.13280, runtime version is 4.0.30319.

And I just noticed that the other app that I did this with has a newer version, 6.30.20288.16410.
I’ll see if that fixes it.

Thanks.
Don

I finally have some sample 3dm files. The original was created with Rhino 7, and the ‘withlandmarks’ file was created with v7 of the 3dmIo library.

The size of the ‘withlandmarks’ is substantially less than the original, but I can’t figure out what’s missing. When I use the debugger in Visual Studio, it looks like everything is there.

I have put a ZIP with the 2 files here:

Thanks.
Don

Hi @don.sayler,

Using Rhino’s Audit3dmFile command, its pretty easy to spot the differences.

Original.3dm

 Block Definition Table:
    block definition[0]: name = "20210927110312939.000030" id = d82f317c-6b51-4d19-b71a-0a7ba851b349
    1 block definitions, 365 bytes (offset 665999 to 666364)
  Object Table:
    object[0]: 13110217 bytes, id = 539594d6-951e-4181-9545-9fb4286f77f7, name = "20210927110312939.000030" (in block definition[0])
    object[1]: 343 bytes, id = caf0ca45-d6c5-4082-9808-b84c7e913ac9, name = ""
    2 objects, 13110584 bytes (offset 666364 to 13776948)

This model contains a single block definition that references a single object. This block as been inserted into the model once.

OriginalwithLandmarks.3dm

  Block Definition Table:
    0 block definitions, 24 bytes (offset 4210 to 4234)
  Object Table:
    object[0]: 13110217 bytes, id = 539594d6-951e-4181-9545-9fb4286f77f7, name = "20210927110312939.000030" (unreferenced block object)
    ....
    23 objects, 13114817 bytes (offset 4234 to 13119051)

This model has no block definitions, but has an unreferenced block definition object. Because it is unreferenced, it is basically hidden in the model. The model also has several point objects.

Does this help?

– Dale

Thanks Dale.

I’m not sure…I’m not really a Rhino expert, I’m not sure what that means.
I’m using the 3dmIo library to create a new model and then copy the info from the original to the new one.

I’ll run the Audit3dmFile command and see what I can figure out.

I got the geometry InstanceReference transferred to the new file.
How do I transfer the BlockDefinition? I can’t find anything in the 3dmIo library for that.

The basic goal of this project is to add those points to the ‘original’ 3dm file. When I just added the points to the file, the mesh was lost also.

Thanks.

Well, this interesting…
I just tried adding the points directly to the existing file. Seems to work in Rhino3dm v7.7.0.0!
I’m gonna test a bit more, but it looks like the problem is solved.

Thanks.
Don