Reasons to model read failure?

Dear all,

I am currently implementing a 3dm Nurbs handler on Linux.
I have an issue with reading 3dm files. I followed the example “example_read”, but I always fall on the “Could not read model” case… Here is my code :

bool onNurbsCurve3dmReader::read(const QString& file){
    FILE* text_fp = ON::OpenFile(file.toStdString().c_str(),"w");
    if ( text_fp ){
        ON_BinaryFile archive(ON::read3dm, text_fp);
        ONX_Model model;
        bool rc = model.Read(archive, NULL);

        if (rc){
            dtkInfo() << "Read model sucessfully";
            return true;
            dtkInfo() << "Could not read model";
            return false;

I am trying to read a simple sphere model.
I tried with different Rhino file format (Rhino 2,3,4,5), created and saved directly from the Rhino 5 interface on windows.

What can be the reason of such a read failure ?

Dear all,

I finally found the issue ! If it can be useful to someone else, here is the solution :
To use this function on a C++ code on linux, and not as a Rhino plug-in, it’s better to use std::fopen instead of ON::OpenFile. Moreover, it’s better to use “rb” instead of “w”.


While I agree with the use of “rb”, instead of “w” for opening binary files for reading, you shouldn’t need to use std::fopen, as ON::OpenFile uses fopen().

I tried and both functions fopen and ON::OpenFile are actually working well

Thanks for your answer,