RhinoDoc.ReadFile fails randomly in 64-bit Rhino

I have a RhinoCommon plugin which I have developed for Rhino 5, using WPF for UI inside a Rhino panel.

One of the functionalities of the plugin is to import geometry from an external CAD file (.3dm or .igs normally). This is triggered by a button-click in my UI.

During development, I have only been testing using Debug32 and had no issues with this feature. However now I’ve come to deploy the plugin, and I am finding that when run in 64-bit Rhino versions, the method RhinoDoc.ReadFile which I use to import the file will sporadically return false, and no data will be imported. Additionally, the behavior seems to be different on different PCs. Here are some examples of how it fails (or doesn’t):

PC 1 (Win 10 64 bit - Debug64 Build - Rhino 5 64-bit)

  • First call fails
  • All subsequent calls succeed

PC 2 (Win 10 64 bit - Release Build - Rhino 5 64-bit)

  • Works as advertised

PC 3 (Win 7 64 bit - Release Build - Rhino 5 64-bit)

  • First call fails
  • Second call succeeds
  • All subsequent calls fail

All PCs Rhino 5 32-bit

  • Works as advertised

Here’s my helper method I use for the import

public static (string filePath, List<Guid> objectIds) GetImportFromFile(string title = "Import File")
{
    var filePath = RhinoGet.GetFileName(
        GetFileNameMode.Import,
        "",
        title,
        RhinoApp.MainApplicationWindow
    );

    if (filePath.Length == 0 || !File.Exists(filePath))
        return (null, new List<Guid>());
        
    Logger.Debug($"Importing file {filePath}");

    var mostRecentObject = Doc.Active.Objects.MostRecentObject();

    if (!RhinoDoc.ReadFile(filePath, new FileReadOptions { ImportMode = true }))
    {
        Logger.Debug("Import Failed");
        return (null, new List<Guid>());
    }

    var importedObjects = Doc.Active.Objects.AllObjectsSince(mostRecentObject?.RuntimeSerialNumber ?? 0);
    var importedObjectIds = importedObjects.Select(rhinoObject => rhinoObject.Id).ToList();

    return (filePath, importedObjectIds);
}

Is there any way I can get more info on what is causing ReadFile to fail?

Hi @david.browne,

What if you just script the Import command using RhinoApp.RunScript?

– Dale

Hi @dale

Thanks for your response.

Yes I’ve tried something along the lines of RhinoApp.RunScript($"-_Import \"{filePath}\"", false);. This does work, however it suppresses the dialog that pops-up if the imported file units don’t match the project units. This is unfortunately the case for a lot of our files (some of which are saved with incorrect units in IGES). However I will revert to using this if I can’t find a solution to the original problem and just handle the units/scaling issue another way.

image

I’ve also considered using just RhinoApp.RunScript("Import", false); which doesn’t suppress the scaling dialog, however this doesn’t give me a way to get the file path (which is used elsewhere in the code).