Can’t find mtl file while using FileObj.Read

Hi all,

I’m getting a message from rhino that it cant find the *.mtl file corresponding to the selected *.obj. Below are first the names of the files. They are in the same folder.

I did some searching on the topic, but could not really find something related.
Can someone explain me what I’m doing wrong? Or point me to a similar topic?

Kind regards Reinder

789982_Osaguona_213063_FOAMBOX_RIGHT_2.obj
789983_Osaguona_213063_FOAMBOX_RIGHT_2.mtl

            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.ShowDialog();
            FileReadOptions fileReadOptions = new FileReadOptions();
            FileObjReadOptions fileObjReadOptions = new 
            FileObjReadOptions(fileReadOptions);
            fileObjReadOptions.MapYtoZ = true;
            fileObjReadOptions.DisplayColorFromObjMaterial = false;
            fileObjReadOptions.IgnoreTextures = false;

            if (openFileDialog.FileName == "")
            {
                return null;
            }
            //create temporary doc
            RhinoDoc doc = Rhino.RhinoDoc.CreateHeadless(null);
            bool IsRead = FileObj.Read(openFileDialog.FileName, doc, fileObjReadOptions);
            List<Mesh> meshes = new List<Mesh>();
            foreach (RhinoObject obj in doc.Objects)
            {
                if (obj.Geometry is Mesh)
                {
                    Mesh mesh = obj.Geometry as Mesh;
                    if (mesh.Vertices.Count < 50)
                    {
                        continue;
                    }
                    meshes.Add(mesh);
                }
            }
            List<Mesh> orderedByVerticeCount = meshes.OrderBy(m => 
            m.Vertices.Count()).ToList();
            FootScanData footScanData = new FootScanData();
            footScanData.Footscan = meshes.ElementAt(0).DuplicateMesh();
            footScanData.Side = side;
            footScanData.Name = $"{side}footscan";
            doc.Dispose();
            return footScanData;

I think i have found the problem. Not sure how to solve it though.

The length of the filename string seems to be to long.
The obj is being read, but the string is altered before reading *.mtl.
the obj string is:
789985_Osaguona_213063_2D_FOOTPRINT_RIGHT_3.obj

the message from rhino is:
Unable to find or open
Osaguona_213063_2D_FOOTPRINT_RIGHT_3.mtl. Materials will be ignored.

Is this logical?

@tim - is this something you can help with?

Hi Reinder,

Upload both to Rhino - Upload to Support and I’ll see if I can make it work better. I should be able to at least tell you what’s going on if it can’t be fixed, although I think it probably can. The OBJ standard specifies 8.3 ascii filenames (it’s old) but I thought I had worked it all out so that’s not an issue on import. I think we don’t try to make short file names on export anymore either .

Cheers,
Tim

Hi Tim,

I’ve uploaded the files. Second try all 3 files obj, mtl, jpg in zip.

Regards Reinder

As a workaround in the meantime, you could shorten the .mtl file name and then edit the .obj file and search for the .mtl file name and shorten that also. But you need a text editor that will work with your .obj file. I just use Windows Notepad but it will not work with large files.

Regards, Terry.

OK. This is happening because your mtl file is named

789986_Osaguona_213063_2D_FOOTPRINT_RIGHT_3.mtl

but the line in your obj file is

mtllib Osaguona_213063_2D_FOOTPRINT_RIGHT_3.mtl

Notice anything missing? If you add “789986_” to the mtllib in your obj file, or rename your mtl file to exclude that, it will read the mtl file. But you still won’t get a texture because the mtl file has the same problem with regard to the image file. The image is named.

789987_Osaguona_213063_2D_FOOTPRINT_RIGHT_3.jpg

But the line in the .mtl file to reference it is

map_Kd var/mobile/Containers/Data/Application/BF2D3EB3-F5F0-487E-B249-37BC0F00F78B/Documents/Osaguona_213063_2D_FOOTPRINT_RIGHT_3.jpg

missing the “789987_”. What app is making these files? You probably want to log that as a bug. It could also be your mobile device that’s adding that. Either way you’ll need to get rid of that prefix, probably easier to rename the file(s).

Hope this helps.

Tim

1 Like

Hi Tim,

I cheked the filenames again with my colleague. He noticed that the prefixnumber of all 3 is different on the last number. This is a print screen of the filenames.

I really need new glasses. Thanks for your effort.

Outlook-e5uxk4xg.png