Hi,
I’m trying to better understand Grasshopper’s solution/computation order when a component modifies a Value List during the solution.
I have a Python component that updates the items in a Value List based on another input. At the end of the update I call:
value_list.ExpireSolution(True)
What I’m not completely clear on is what happens during that solution.
In other words, is the definition effectively being computed twice in this situation?
Or does Grasshopper somehow update the Value List before downstream components are evaluated, so only the final updated value propagates through the definition?
I’m mainly trying to understand whether modifying and expiring a Value List from inside a running solution can cause downstream components to briefly compute with the old value before the new solution starts.
Any explanation of how Grasshopper schedules this internally would be really helpful.
Thanks!
from Grasshopper.Kernel.Special import GH_ValueList, GH_ValueListItem
ghenv.Component.Message = "Height Value List v3"
HMin = 3
doc = ghenv.Component.OnPingDocument()
def update_value_list(name, width):
value_list = next((obj for obj in doc.Objects if isinstance(obj, GH_ValueList) and obj.NickName == name), None)
h_max = 22 - int(width)
if value_list is None:
return h_max
current = next((int(item.Expression) for item in value_list.ListItems if item.Selected), HMin)
current = max(HMin, min(current, h_max))
values = list(range(HMin, h_max + 1))
existing = [int(item.Expression) for item in value_list.ListItems]
if existing != values:
value_list.ListItems.Clear()
for value in values:
item = GH_ValueListItem(str(value), str(value))
item.Selected = value == current
value_list.ListItems.Add(item)
value_list.ExpireSolution(True)
return h_max
height_max = update_value_list("Height", Width)
Report = "Height allowed range modified to {} to {} because of Width = {}".format(HMin, height_max, Width)
