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.
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 ?
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?
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)
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:
Drag a gh-file into Grasshopper from Windows (or Mac).
Show the Human UI forms which are defined in this file.
Wait for the user to click on some button on these Human UI forms.
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.
Unload the gh document without saving any changes made to it, so we’re now back into the starting state from before step (1).
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.”
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…
I was just in need of this myself (for a one-click Recompute Solution from the RCP) and ended up here. I’m not sure if this GHPython approach (based on David’s advice above) would be considered super correct, but it does appear to do the trick:
def ghSolutionRecompute():
""" Recomputes the Grasshopper solution (ala pressing F5) """
def expireAllComponentsButThis(e):
for obj in ghenv.Component.OnPingDocument().Objects:
if not obj.InstanceGuid == ghenv.Component.InstanceGuid:
obj.ExpireSolution(False)
ghenv.Component.OnPingDocument().ScheduleSolution(1000,expireAllComponentsButThis)