Wide strings in Rhino script doesn't work as intended

Hello devs!

I have this code below:
std::wstring stdwstr(stdstr.begin(), stdstr.end()); ON_wString script; script.Format(L"_-Open \"%ls\" _Enter", stdwstr.c_str()); RhinoApp().RunScript(context.m_doc.RuntimeSerialNumber(), script.Array());
where stdstr = is a std::string

The resulting command in Rhino is three different commands:
1- _-Open
2- The path passed to format
3- _Enter

Is there a reason why this is happening? And what’s the sane way to work with those wide strings that complicate all the code base?


Hi @blondbeer,

I’m not sure completely understand the question. But if you are just looking to script Rhino’s Open command from a plug-in command, you might have a look at cmdSampleOpen3dmFile.cpp.

Otherwise, have a look a the ON_String and ON_wString classes in opennurbs_string.h.

CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
  std::string path = "C:\\Users\\Dale\\Desktop\\test.3dm";
  ON_wString wscript, wpath = path.c_str();
  wscript.Format(L"_-Open \"%ls\" _Enter", static_cast<const wchar_t*>(wpath));
  RhinoApp().RunScript(context.m_doc.RuntimeSerialNumber(), static_cast<const wchar_t*>(wscript), 0);
  return CRhinoCommand::success;

As for support for std strings, you might read through opennurbs_std_string.h and see if you can gleam anything.

– Dale