Matlab - Grasshopper Interaction (Advanced)

I need to pass data back and forth repeatedly between Grasshopper and MATLAB.

In this post, Mostapha showed one way of doing this. This works, however the method seems a bit slow and prone to errors since it relies on writing and deleting a file, using pause() functions and a Grasshopper timer. He does mention:

Note: Obviously this method is not the most sophisticated method that you can use but it is simple enough to set-up easily and fast.

So my question is: What is a more sophisticated way of doing this?

All the best,

@MaxMarschall The post you mention is 6 years ago. Could you tell what are going to do for Matlab - Grasshopper Interaction .If only for visualization and basic statics, Grasshooper is enough for you.

Hi @minggangyin,

It has to do with some dynamic energy simulations that I am running.

The setup was a bit too complicated to explain here, but in essence: I need to create a loop where I compute something in Grasshopper (or GHPython), send the results to Matlab, compute something in Matlab based on that data, then send results back to Grasshopper and so on.

The tricky thing here seems to be the timing. I’d like Grasshopper and Matlab to each “know” when the other has finished its operation, and only then immediately do their own operation. Is that even possible?

It should be doable in principle. The key here will be using the timer component in grasshopper.

  1. Do the process in gh to register data somewhere (preferably excel)
  2. Observe the time for the first step to get finished.
  3. Setup a timer component for time greater than or equal to step 02
  4. Read the data back into grasshopper once it has been processed with Matlab
    test.xlsx (7.7 KB) (20.0 KB)

Is it possible to compile your Matlab code and run it as an executable? That can make everything much cleaner as you can run Matlab as a subprocess and wait for it to be finished.

Thanks for your answers. In my case the subprocess idea might work. I’ll give that a shot and post back with the solution if I succeed.

As I know, you should first install the matlab.engine API for python, then use the GHCpython component( to link the two.

1 Like