Recompute Button

humanui
#1

Hi
trying to find something that I thought will be easy to find, but finally not…
using a button to recompute all the grasshopper document.
I want the exact same result as if I was using the F5 on my keyboard.

I have tried many different small script, but due to my lake off skills I can’t make them works.

1- C# script originally created to recompute some selected object :
http://james-ramsden.com/force-a-component-to-re-compute-in-grasshopper/

modified by myself this way :
C-recompute-2.gh (1.8 KB)
when it’s inside my .gh file it works way too much, recomputing over and over (probably as many times as there are objects in the gh file, is there any way to make it loop only one time ?

2- this seems interessant but just don’t know where to paste “expire” on a C# code…
https://discourse.mcneel.com/t/lock-recompute-bool/81839

3- SOMEBODY TALK ABOUT GH_Document.ExpireSolution(true) :
https://www.grasshopper3d.com/forum/topics/recompute-from-custom-component?commentId=2985220%3AComment%3A1008128
which is not working when I do it myself do I have to call a special “library” ?
C-recompute.gh (1.8 KB)

After a lot of research… it’s appear that I don’t understand anything to the answers already given 5 years ago…

I want to link it with a value listener in Human UI to create a kind of application / software usable by dummies :slight_smile: -> like me

any help will be appreciate…

(David Rutten) #2

GH_Document.ExpireSolution(true) is the correct approach, but you cannot call this from within your script. After all, calling that method would run your script again right away, which would recompute the file, which would run your script, which would recompute the file, which would run your script, which would recompute the file, which would run your script, which would recompute the file, which would run your script, which would recompute the file, which would run your script, … boom, stackoverflow crash.

You cannot start a solution while you are part of a solution, c’est interdit.

What you can do if you have no UI, is schedule a new solution and in the schedule callback expire all objects. If you do have a UI (like Human), then you don’t have to worry about running inside a solution because your code will be running inside event handlers instead, such as ButtonClick or MouseMove.

Based on the comments in your file, it seems you only want to expire selected components, not all components. Is that correct?

ps. May I ask why? Are these components not expiring themselves when they should?

#3

thx for your answer, I do not really undersand your answer, this time it’s an english skills lake…
I do understand the loop idea that a recompute button create as long as it stay on “True” value, if when recomputing one time the value is then False… is there still a problem ?

What I exactly need is a kind of F5 shortcut, due to the fact that there is many people using thoose tools and some of them don’t understand nothing to grasshopper. If it’s possible I want the .gh file to open, the Human UI interface to appear and they just don’t have to go deeper inside GH.

I basically want to recompute all the file… it’s is particularly made for a .csv and .geo export .gh file, and many people drag and drop a new file into the already open rhino, press the bake button again and don’t understand why the 2 gmsh are the same… (because they don’t recompute before pressing bake button again)

(David Rutten) #4

Solutions in Grasshopper 1.0 run on the UI thread, so while solutions are running back-to-back (or even inside each other) there will be no way to process a mouse event on some button. You can terminate the infinite regression through code, but are you sure you’re going to get it right before Windows decides to kill Rhino because it has used up the call-stack memory?

I’m no expert about Human UI plug-in (in fact I know almost nothing about it), but do I understand correctly that the process you’re after is:

  1. Drag a gh-file into Grasshopper from Windows (or Mac).
  2. Show the Human UI forms which are defined in this file.
  3. Wait for the user to click on some button on these Human UI forms.
  4. Perform a solution, which may involve reading data from files on the disk, baking geometry into Rhino, and writing data to files on the disk.
  5. Unload the gh document without saving any changes made to it, so we’re now back into the starting state from before step (1).

Or is it:

  1. Drag a gh-file into Grasshopper.
  2. Show the Human UI forms defined in this file.
  3. Let the user specify settings on this form.
  4. Press some button you define and control.
  5. Run the entire solution.
  6. Close the gh file without saving.

Or…?

(Andrew Heumann) #5

You should not call recompute on the entire document while the Human UI window is open - because this will recompute the window as well! If you absolutely must recompute certain components in the definition, use MetaHopper “Expire Object” component to do this dynamically - just feed it a list of all the objects you need to “force refresh.”

#6

they do (and me too) it this way :
1- open assembly1.3dm
2- launch grasshopper and .geo/csv export tool (so grasshopper automically recompute when it open)
3- press the bake button into grasshopper
4- reduce the grasshopper tool tiking the top right cross
5- drag and drop assembly2.3dm
6- callback grashopper pressing the grasshopper button into rhino
7- at this step grasshopper will not recompute automatically, so I do a F5, but the other guy didn’t
8- the press bake button and bake the older solution again (witch automatically create a file named assembly2.geo and assembly2.csv (the name is given by a small VB box who seems to be the only one recomputing by itself). even if the nam of the file change, the content still the older one…

#7

i try this, and it seems to work… !

thx

2 Likes