Let Grasshopper/Python change Value "X" until it matches "Y"

Hello,

I have made a setup in Grasshopper in which a Knob can be changed. At the moment, I manually adjust the Knob until I get the desired value. Now, I would like to know if i can automate this process. I want python to turn the Knob until the volume matches the desired volume.

Does anyone know how to write a script for this?

Raltena

Volume.gh (9.7 KB)

You could use one of the optimization plug-ins in Grasshopper for this (e.g. Galapagos, Goat, Opossum), but I’m not sure that’s what you need.

It will be difficult with Python in Grasshopper because you need to “close the loop”, which is not possible in Vanilla Grasshopper. (But you could try to do this with Hopesnake, or another plug-in that allows loops.)

Or you just write this as a Python script outside of Grasshopper, with a “while” loop,

Hi @raltena,

It would help if you could post the meshes here on Discourse, to provide some data to work with. Best way would be to internalise them into the mesh components (right click on each mesh component and select the Internalise Data option) and resubmit your .gh file.

Regards
Jeremy

Thanks for your Reply

i’ll try if your suggestion will help me any further

Thanks for your reply Thomas,

As I have no additional plugins available, this option is not possible for me. Scripting is not something I exel in either. As you say, what I want is not possible in Grasshopper/phyton alone, then this is already some valuable information :slight_smile: lt means I can try to go find otherways to solve the problem.

Hi Raltena,

I’m not sure what you mean with “not available”.
Galapagos is inbuilt in Grasshopper, and other plug-ins are available for www.food4rhino.com.

Cheers,
Thomas

Hi Thomas,

I didn’t know that, That will change some things maybe :smiley: I’ll have a look and see if I can make use of Galapagos for my problem.

As I’m just starting with Grasshopper, replies like yours are very helpful to me!

Thanks again!

Hi Thomas,

Do you have any suggestions on how to make galapagos find smaller values? I have a working setup now but i would like to receive more precise answers. I expected Galapagos to start iterating, and refine and refine each iteration, decreasing the range of numbers to be checked to eventually minimize to values with like 0,01 precision. If im lucky it will get to 0,1

I would ask Galapagos to minimize the difference between the current value and the desired value - that should do it.

If the results are not precise enough, I would try some of the algorithms from Goat and/or Opossum (both on food4rhino).

Your suggestion is what I have done as well, I have volume A and B where I want A to equal B, So I subtracted B from A and made an absolute value of the resulting value. I told Galapagos to minimise this value, because if its zero, A equals B.

So I’ll take a look at your suggested algorithms and see if they make a difference.