I am working on a ship hull optimization project. Initially I started with Grasshopper plugin motivated by this post. However, later found another plugin called Orca3D which can be used along with Rhinoscript to generate a parametric ship hull. I have written a Rhinoscript to generate parametric hull by reading parameters from a CSV file stored at a specific location. The idea was to use Grasshopper to check for new CSV file in the given location, if found it would wake up the Rhinoscript to generate new hull form.
At this point, before moving forward with Matlab + Grasshopper + Rhinoceros + Orca3D combination, I would like to know if this is absolutely necessary. Is there a way to communicate with Rhinoceros directly from Matlab? If not, will it be efficient to run a perpetual while loop in Rhinoscript which will continue to look for the existence of a new CSV parameter file and if found, it will start the Rhinoscript?
I guess it’s not possible to have any direct matlab connection with Rhino then.
As a workaround, I am writing one MatlabToRhino.cvs file from matlab and running an while loop in rhino to look for the CSV file. When the CSV file found, rhino runs its functions and deletes the MatlabToRhino.csv file and creates a RhinoToMatlab.csv file. I have an while loop running in Matlab which keeps looking for the RhinoToMatlab.csv file and runs its function when this file is found and deletes RhinoToMatlab.csv file.
This way, both Matlab and Rhino pass variables between each other. This method is a workaround for the time being.
Please let me know if someone has a better, more efficient way of doing this.
It may be that no one here (on this forum) has any experience with Matlab. If this works at all, my guess would be that the work flow would be running Rhino and connecting to Matlab, either through a Rhino plug-in or a Grasshopper component.
some time ago, I experimented with Grasshopper and Matlab. I wrote a Grasshopper plugin that called a Matlab optimization algorithm via the Matlab programming interface. Then, Matlab was able to use my own target function and constraints (written in C#) in its optimization and returned the result to the Grasshopper plugin.
There were no intermediate .csv or other files. The results were very fast and stable. And I had great support from the guys from Matlab.
Unfortunately, you will need a developers license of Matlab (about 10000€ for developers license and optimization package). So, I had to stop testing…
Thank you @Enza for sharing your experience. I thought I should mention the final solution I have accepted for my current project here.
I have created a rhino script Main.rvb which calls various other functions inside. From Matlab I run Rhinoceros using (!) bang character and load all the scripts and then run the Main script. The Main script also has a Rhino.exit() call, at the end of the script which closes Rhino automatically. This way, I can call Rhino in every iteration, run to obtain a new shape and then close it.
It’s understandable that this method will not be as efficient as directly working from Rhino would be, but I am more comfortable with Matlab where most of the other calculations happen. The whole opening RHino, ship hull generation, panelization, saving the model and closing Rhino takes about 30 seconds on my desktop (18 sec in my new laptop).
The Matlab COM object is also able to connect to Rhino, but there is no function that is supported by Rhino for Matlab at the moment. So, I could just connect and open Rhino using the COM object, nothing further.
Here’s the sample code for running Rhino from Matlab:
I find that your project is much more complicated.
And I also have a same project now.
I use matlab to calculate some data.Then I want to put these numbers to Rhino and creat a curve. At last I want to save this curve as a .sat file. I want to do this automatically from matlab. Can you give me some advice？
You can write a CSV file through Matlab and read it from Rhinoceros. Please find attached a sample rhino script that reads a csv fiile and stores the values in a variable. Once the values are stored, you can use them for creating your curves.
Hello. Thank you for mentioning your question on rhinoceros forums and the last solution. I am involved in Civil engineering. My research subject is optimization of topology.
I’ve already optimized the matlab script file, so I want to change this pattern in rhinoceros now. How do I automatically insert this optimized Matlab folder to rhinoceros? YOU asked HOW TO RUN RHINOSCRIPT FROM MATLAB.
Now I’d like to know how to run matlab rhinoscript. Can you explain this to me?
I can’t understand your ultimate solution.
<<<<I have created a rhino script Main.rvb which calls various other functions inside. From Matlab I run Rhinoceros using (!) bang character and load all the scripts and then run the Main script. The Main script also has a Rhino.exit() call, at the end of the script which closes Rhino automatically. This way, I can call Rhino in every iteration, run to obtain a new shape and then close it.>>>>
May I communicate with you using Facebook or Instagram? It’s going to be easier
To do this you will need to write a Matlab script or scripts to save the data from Matlab and then launch Rhino and a Rhino script to load the saved data and do the geometric operations. You can tell Rhino to execute your script automatically on startup.
If you want to iterate multiple times then you also need to save data back from your Rhino script and load it into Matlab again, and so on…
Do you know how to write scripts in Rhino? You have multiple options, including Python, RhinoScript(i.e. VBScript) and C#. If you don’t know any of them then I think Python is most similar to Matlab scripting.
See my previous post with an example Rhino script to read a CSV file. I used MATLAB to generate input values, and then used system command ! to run Rhinoscript. Below are the steps I followed:
Step 1: Run Matlab to generate input data points CSV file. Call Rhinoscript from Matlab using the ! command
Step 2: Perform geometric operations using Rhinoscript such as: develop CAD model, split the model, create panel mesh, save in a particular format.Close Rhino.
Step 3: I keep checking existence of the file saved in Step 2 from Matlab. Once this file is available, I move it to another location to perform further analysis (e.g. Hydrodynamic load calculations). I use this as a trigger to run my optimization loop.