For a project I want to programmatically create geometry, export the file to a particular format (.gdf), and then use the file in another program.
I would like the script that does this to be called by another program (Matlab), without opening Rhino. I am running a genetic algorithm in Matlab to optimize geometry.
The only way you can call into Rhino externally is using ActiveX (COM) automation. And, Rhino itself doesn’t expose much in the way of objects, properties, or methods. But you can access the RhinoScript object via automation. You can also write Rhino plug-ins that expose objects too.
Hi Dale, thank you very much for your reply. If I understand you correctly, at the very least I could run a RhinoScript. Maybe you could help me with this script.
This is basically what I want to do for the project, but obviously have much more complex surfaces. I am having trouble with the _SaveAs Command. Is there a way to include the optional arguments as part of the command:
Dim i
Dim x, y, z
Dim xs, ys
Dim arrPts(3)
Dim strFileName, strCommand
xs = Array(-10, 10, 10, -10)
ys = Array(10, 10, -10, -10)
For i = 0 To 3
'Rhino.Print "Point " & (i + 1)
'x = Rhino.GetReal("x")
'y = Rhino.GetReal("y")
'z = Rhino.GetReal("z")
x = xs(i)
y = ys(i)
z = 0
arrPts(i) = Array(x, y, z)
Next
Rhino.AddSrfPt arrPts
' Making the extension .gdf saves the file in the format I want
' The format has some options that are e
strFileName = "C:\WAMIT\surf.gdf"
' This works but I have to manually hit enter to complete the command
strCommand = "_-SaveAs " & strFileName
' This does not work, but it is what I want to do
strCommand = "_-SaveAs " & strFileName & "X=No, Y=No, G=9.81 _Enter"
Call Rhino.Command(strCommand, 0)
And I’m running into a couple of problems. It creates the instance of Rhino, opens the program, and I’ve been able to run some rhino.RunScript commands.
But it doesn’t run the SampleCsRhino plug-in command. i.e. rhino.RunScript("_-SampleCsRhinoCommand", 0); returns: Unknown command: _-SampleCsRhinoCommand at the Rhino command line.
And plugin = rhino.GetPlugInObject(pluginId, pluginId); returns null.
Follow up question: Are there limits (or what are the limits) to what you can do with RhinoCommon without a Rhino application being open (or outside a Plug-In)?
For example, I am trying to run the following code inside a console application (from here):
Rhino.Geometry.Point3d center_point = new Rhino.Geometry.Point3d(0, 0, 0);
Rhino.Geometry.Point3d height_point = new Rhino.Geometry.Point3d(0, 0, 10);
Rhino.Geometry.Vector3d zaxis = height_point - center_point;
Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(center_point, zaxis);
const double radius = 5;
Rhino.Geometry.Circle circle = new Rhino.Geometry.Circle(plane, radius);
Rhino.Geometry.Cylinder cylinder = new Rhino.Geometry.Cylinder(circle, zaxis.Length);
Rhino.Geometry.Brep brep = cylinder.ToBrep(true, true);
It runs until it gets to: Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(center_point, zaxis);, and then I get the error:
An unhandled exception of type ‘System.DllNotFoundException’ occurred in RhinoCommon.dll
Additional information: Unable to load DLL ‘rhcommon_c’: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Can I create an abstract base plug-in (BasePlugIn : PlugIn) in one library (DLL), and then create derived plug-ins (AnotherPlugIn : BasePlugIn) in other libraries?
Really, what I want to do is have a set of plug-ins that do different things, each in their own library, but they share a lot of common functionality.