RhinoApp.Runscript not working in C# script from toolbar

I am trying to use RhinoApp.Runscript inside a C# script.

When I hit the ‘Run’ button inside the ScriptEditor, it works perfectly.
However I would like to assign the script to a toolbar button, with the macro

-ScriptEditor _run “myscript.cs”

Then the script fails. Probably the command ScriptEditor should be a ScriptRunner command for it to work ?

Is there another way to execute a C# script from a toolbar button ?

Hi @i-Shape,

Make sure to full path the script file.

For example:

_-ScriptEditor _Run "C:\Users\Dale\Downloads\example.cs"

– Dale

Hi Dale,

Sorry if my question was not clear. The correct path was not the problem.

I meant there is a ‘RhinoApp.Runscript’ statement inside the C# script, which fails to execute when the script is run from a macro. Like in the simplified example script below.

So I repeat my question, how could I assign this C# script to a toolbar button ?

using System;
using System.Diagnostics;
using Rhino;

int radius = 100;
bool sts = Rhino.RhinoApp.RunScript($“-Circle 0,0,0 {radius}”, true);
if (sts)
RhinoDoc.ActiveDoc.Views.Redraw();

Thanks in advance

This bug report applies to Python 3 scripts, also.

Calls to RhinoApp.Runscript work when run from the IDE, but fail when the same script is run from the command line.

This applies to Python 3 , Rhino 8.3 running on Windows computer.

If the echo parameter for RhinoApp.Runscript function is set to True the code will echo the script component’s text to the command line but the Function itself returns False and fails to execute.

RhinoApp.Runscript functions seem to work fine in IronPython when running them using RunPythonScript in Rhino 8.3.

@i-Shape, @jim,

I’ve logged the issue so we can look into what you’ve reported.

https://mcneel.myjetbrains.com/youtrack/issue/RH-79530

Thanks,

– Dale

RH-79530 is fixed in Rhino 8 Service Release 4 Release Candidate

Hi, I have Version 8 SR17 and I have the same problem. The script runs fine from the editor ‘play button’, but !-_ScriptEditor _Run "path\to\my\script.cs" prints ‘Compile Error’.

@Becquelin What’s in the script that throws Compile Error?

Hi @eirannejad.
Nothing! That’s the point! This script below works when I press the play button, but fails if I try to launch it from the command line.

using System;

using Rhino;

Console.WriteLine("Testing CS");

Hmm odd. Okay let me take a look:

  • Is this macOS or Windows?
  • Does it work if you add // #! csharp to the top of the script?

Oh sorry I forgot to mention it’s on Windows.
No the // #! csharp hint is there and doesn’t help.

1 Like

Okay one quick last check. Would you mind testing this in 8.18 SRC as well? Just want to make sure the issue is persisting. Asking since it works for me here:

Yes it works in SRC18.

1 Like

Sweet. Thanks for checking!