C++ Mesh.IsValid

Hi,

I am trying to know why mesh is not valid.
When I print the string I get not this output not a correct message.
How can I print correctly the log of the mesh.IsValid output?

ON_wString str;
    ON_TextLog log(str);
    bool isValid = RhinoMesh.IsValid(&log);
    if (isValid) {
        std::cout << std::endl << "Valid Mesh" << std::endl;
    }
    else {
        std::cout << std::endl << "Not-valid Mesh " << (L"%s\n", static_cast<const wchar_t*>(str));
}

What I see in console is this weird index:
Not-valid Mesh 000002AEF786AC3C

The easiest way is to just do this:

ON_TextLog dump_to_stdout;
mesh.IsValid(&dump_to_stdout);

And there is also this:

ON_wString error;
ON_TextLog error_log(error);
if (!mesh.IsValid(&error_log))
{
  ON_TextLog dump_to_stdout;
  dump_to_stdout.Print(L"Mesh is invalid: %ls\n", static_cast<const wchar_t*>(error));
}

– Dale

1 Like

Thank you Dale, you always help me!

Is there a way to print string directly from ON_TextLog dump_to_stdout in one line :

ON_TextLog dump_to_stdout;
mesh.IsValid(&dump_to_stdout);
std::cout << dump_to_stdout; //For sure this does not work because it is not a string

or I need to do this extra step:

ON_TextLog dump_to_stdout;
  dump_to_stdout.Print(L"Mesh is invalid: %ls\n", static_cast<const wchar_t*>(error));
}

The second options works perfectly.