Incomplete Rhino command when invoked from C++

Hello,

I have the following code invoked from C++ after a user action to load a model into Rhino:
` CRhinoGetFileDialog gf;
gf.SetScriptMode(context.IsInteractive() ? FALSE : TRUE);
bool rc = gf.DisplayFileDialog(CRhinoGetFileDialog::open_dialog, nullptr, RhinoApp().MainWnd());
if (!rc)
{
return CRhinoCommand::cancel;
}

ON_wString filename = gf.FileName();
filename.TrimLeftAndRight();
if (filename.IsEmpty())
{
return CRhinoCommand::nothing;
}

if( !CRhinoFileUtilities::FileExists(filename) )
{
RhinoApp().Print( L"File not found.\n" );
return CRhinoCommand::failure;
}

ON_wString script;
script.Format(L"_-Open “%ls” _Enter", filename);
RhinoApp().RunScript(context.m_doc.RuntimeSerialNumber(), script);`

The model is failing to load, and the output is Rhino is just Command: _Open, as if the rest of the script (the path to the file to load) is being trimmed and lost somewhere.
What am I missing here?

Thanks

Does this help?

— Dale

I think the problem is here:

ON_wString filename = gf.FileName();
// <snip>
ON_wString script;
script.Format(L"_-Open “%ls” _Enter", filename); // don't use ON_wString as input for formatting

Probably your compiler already warns you about it. You should I think use this:

ON_wString filename = gf.FileName();
// <snip>
ON_wString script;
script.Format(L"_-Open “%ls” _Enter", filename.Array()); // Do this instead, provide the raw wchar_t* array for formatting.

Also, it looks like you’re using curly double quotes, but that may also be a copy-paste thing.
With that, you should format like so, escaping the double-quotes inside the format string:

script.Format(L"_-Open \"%ls\" _Enter", filename.Array());

Yes! Thank you for pointing that out!