Rhino Plugin Making


unsigned int serial_number = context.m_doc.RuntimeSerialNumber();
const wchar_t* myScript = L"_Box 0,0,0 10,10,10";

CRhinoScriptContext s = CRhinoScriptContext();
s.SetScript(L"_-Line 0,0,0 10,10,10");

bool result = RhinoApp().RunScript(serial_number, myScript, 1);
if (result)
    RhinoApp().Print(L"Script executed successfully!\n");
    return CRhinoCommand::success;
    RhinoApp().Print(L"Script execution failed.\n");
    return CRhinoCommand::failure;

I have no idea why it cannot make a box and line. I want to run any command in rhino but, result of Runscript is always false. There is not any error, but it always fail to execute command.

I use Rhino7, SDK7, and Visual Studio2019.

Please help…

For me:
It also fails for me when I do something like

        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
            RhinoApp.RunScript(doc.RuntimeSerialNumber, "_-Circle 5,5 10", true);

                        return Result.Success;

It succeeds for me when Rhino is not in the middle of executing a command. When you try to run that script, Rhino still thinks it’s executing the “YourCommandName” command when you make the script call.

When I do this, which is run from a button click on my own user form, it creates a circle:

        private void OnClickAdd(object sender, EventArgs e)
            RhinoApp.RunScript("_-Circle 5,5 10", false);

I’m afraid that I don’t know how to run a script directly when one of my own plugin commands is being executed.

Putting a “!” in front to cancel the previous command doesn’t seem to work.

If I were you, I’d probably try something like storing the script and executing it next time Rhino fires the Idle event.

1 Like

Both in C++ and in C# the command must be marked as a “script runner” command to be able to use the RunScript approach. In C++ this is done by overriding the IsScriptRunnerCommand() function in the command class, in C# it is done with an attribute applied to the command class called CommandStyle.ScriptRunner.