Hi
I am trying to do something similar to what is happening here but using python.
I have come with this code so far, but when executed I receive the object expired during a solution error.
import Grasshopper as gh
import random
GrasshopperDocument = gh.Instances.ActiveCanvas.Document
#####
# Define the Functions
#####
def FindSliders():
input = ghenv.Component.Params.Input[1]
sliders = []
for source in input.Sources:
if source is not None:
sliders.append(source)
return sliders
def FindParam():
input = ghenv.Component.Params.Input[0]
for source in input.Sources:
if source is not None:
return source
else:
return None
def ScheduleCallback():
for i in range(0, int(iterations)):
for slider in sliders:
slider.SetSliderValue(random.random() * 10)
#####
# Main Code
#####
running = False
if not running:
running = True
iterations = max(Runs, 1)
sliders = FindSliders()
param = FindParam()
if iterations > 0:
GrasshopperDocument.ScheduleSolution(10, ScheduleCallback())
else:
running = False
I can avoid the expired during solution window if I use slider.Slider.Value
instead of slider.SetSliderValue(),
but the sliders go crazy and do not stop changing values as expected per the number in Runs
.
I know running
should be decrementing with each loop, but putting a while
loop with a decrement in ScheduleCallback()
does not do work.
Any ideas on how to make my code work as expected?
Thanks