I am doing RHINO test automation, when importing a DWG file, RHINO always pops up a prompt asking me to confirm, how to turn off this prompt? Or how to confirm this prompt with code?
Are you using a - (hyphen) in front of the command name? That puts the command in âscripting modeâ. Then you can put the options on the command line from code.
Thanks
Hello, I am trying to import stl files using
Rhino.RhinoDoc.ActiveDoc.Import(modelPath);
Is there a another way than
Rhino.RhinoApp.RunScript(...)
to get rid of the prompt and proceed with default values or to specify the import options?
As written above, use a hyphen in front of the command name. This will put the command in scripted mode, which allows the options to be set as part of the script.
Something like this should work:
RhinoApp.RunScript("_-Import testImport.stl Weld=Yes SplitDisjointMeshes=No _EnterEnd")
Thank you for your answer, but I really should have given more context.
I am building a application that interfaces rhino with a node server using edge, so I first tried with the API import command as it felt the more natural for me. Maybe it does work for formats other thatn STL that do not require option settings?
Anyway then I tried the RhinoApp.RunScript(
way and even after I got the syntax Ok :
string strFileName = "C:\testImport.stl";
result = Rhino.RhinoApp.RunScript("_-Import " + '\u0022' + strFileName + '\u0022' + " _ModelUnits=_Millimeters _Enter", true);
Nothing is logged in rhinoâs console as if the command was not called and the boolean result is false. Whereas if I paste the command printed in my console in rhinoâs command bar it does work.
_-Import "C:\testImport.stl" _ModelUnits=_Millimeters _Enter
I also tried with
result = Rhino.RhinoApp.RunScript("_-Line 0,0,0 -10,-10,-10", true);
still nothing int rhinoâs command log
To be thorough when Rhino is getting started I use Rhino.RhinoApp.RunScript(" to start grasshopper and it does work at that time. Somehting might be blocking commands later on.
Any idea how to debug this or import stl files another way?
Thank you very much,
Olivier
Hi, If you are trying to run this script from a plug-in context, this page might help : Run a Rhino command from a Plugin with C#
Thank you Aymeric, I tried adding
[Rhino.Commands.CommandStyle(Rhino.Commands.Style.ScriptRunner)]
But it had no effect
Hi @roievil,
Try this:
[CommandStyle(Style.ScriptRunner)]
public class TestRoievil : Command
{
public override string EnglishName => "TestRoievil";
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
var path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var filename = Path.Combine(path, "Test.stl");
if (!System.IO.File.Exists(filename))
{
RhinoApp.WriteLine("File not found.");
return Result.Failure;
}
// Make sure to surround filename string with double-quote characters
// in case the path contains spaces.
var script = string.Format("_-Import \"{0}\" _ModelUnits=_Millimeters _Enter", filename);
RhinoApp.RunScript(script, false);
return Result.Success;
}
}
â Dale
Hello Dale,
Thank you very much for your answer. I am having trouble testing it :
How should I execute that command?
Here is the adapted code I want to test :
using Rhino.DocObjects;
using Rhino.FileIO;
using Rhino.Commands;
using Rhino;
namespace InsideNode
{
[CommandStyle(Style.ScriptRunner)]
public class TestRoievil : Command
{
public override string EnglishName => "TestRoievil";
public string modelPath;
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode)
{
Rhino.RhinoApp.WriteLine("From STLImport.cs, Trying to Import the following model" + modelPath);
//var path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
//var filename = Path.Combine(path, "Test.stl");
if (!System.IO.File.Exists(modelPath))
{
Rhino.RhinoApp.WriteLine("File not found.");
return Result.Failure;
}
// Make sure to surround filename string with double-quote characters
// in case the path contains spaces.
var script = string.Format("_-Import \"{0}\" _ModelUnits=_Millimeters _Enter", modelPath);
Rhino.RhinoApp.RunScript(script, false);
return Result.Success;
}
}
}
Here is what I tried
TestRoievil cmd = new TestRoievil();
cmd.modelPath = modelPath;
Rhino.Commands.Result r = Rhino.RhinoApp.ExecuteCommand(Rhino.RhinoDoc.ActiveDoc, "TestRoievil");
Rhino.RhinoApp.WriteLine("commandResult " + r);
But obviously thatâs not it I get an unknown command, also my path is dynamic so I have to pass it.
Thank you very much for you help !
Olivier
Launch Rhino, load your plug-in, and run TestRoievil
. Does this work?
â Dale
Ok I am interacting with rhino through a library so I cannot type any command I have to do it programatically.
The user submits a file to be opened/imported in rhino
When the imported file is a 3dm File I am able to open it via Rhino.FileIO.file3dmâŠ
if (threedm)
{
//Read the 3dm file
Console.WriteLine("reading 3dm file" + modelFileName);
file = Rhino.FileIO.File3dm.ReadWithLog(modelPath, out errorLog);
Console.WriteLine("file3dm errorLog" + errorLog);
}
if it is an STL I would like to have the same kind of process,
if (threedm)
{
...
} else {
// import the STL file
}
but when I try with
Rhino.RhinoDoc.ActiveDoc.Import(modelPath);
The workflow is stopped in rhino because it requests import options
if I try with
string strFileName = "C:\testImport.stl";
result = Rhino.RhinoApp.RunScript("_-Import " + '\u0022' + strFileName + '\u0022' + " _ModelUnits=_Millimeters _Enter", true);
I get nothing in rhinoâs command history, and the result of the runScript is false.
Although If I paste the above script in rhino it works, and If I runscript another command like
result = Rhino.RhinoApp.RunScript("_-Line 0,0,0 -10,-10,-10", true);
it does work.
.
.
With the solution you proposed why do I get âUnknown command: TestRoievilâ when I try
Rhino.Commands.Result r = Rhino.RhinoApp.ExecuteCommand(Rhino.RhinoDoc.ActiveDoc, "TestRoievil");
Rhino.RhinoApp.WriteLine("commandResult " + r);
Do I have to register / add the TestRoievil class somewhere special ?
Thank you,
Olivier
Rhino must be aware of your plug-in. This is stored in the registry the first time you load the plug-in. Loading the plug-in is achieved by dragging the RHP file onto rhino. Upon restarting rhino, it will scan the registry and find information about your plug-in, and know about the command(s) in your plug-in.
Hello, Thank you for your answer, the thing is there is no âplug-inâ, no file, I am using Rhino.Inside and edge to interact with rhino.
so I would need a programmatically way to register the
public class TestRoievil : Command
And I did not find it in rhinoCommon
Do you know of such thing?
.
.
Basically how do you import an STL from rhino inside?
typically I would use FileIO but it seems that STL files are not supported
Thank you very much
Olivier