Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// The usual setup
protected override void SolveInstance(IGH_DataAccess DA)
{
// More standard setup
int index = this.Params.IndexOfInputParam("Inputs");
List<IGH_Param> L = this.Params.Input[index].Sources.ToList();
doc = Grasshopper.Instances.ActiveCanvas.Document;
if (runCount < MAX_RUN) // MAX_RUN = 20, runCount starts with 0
{
doc.SolutionEnd += OnSolutionEnd;
}
DA.SetData(0, GenerateLog(L)); // Just sets the output of slider values
}
private void OnSolutionEnd(object sender, GH_SolutionEventArgs e)
{
if (runCount >= MAX_RUN)
{
e.Document.RequestAbortSolution();
e.Document.SolutionEnd -= OnSolutionEnd;
return;
}
if(runCount < MAX_RUN)
{
int index = this.Params.IndexOfInputParam("Inputs");
List<IGH_Param> L = this.Params.Input[index].Sources.ToList();
LoopThroughSliders(e.Document, L);
e.Document.NewSolution(false, GH_SolutionMode.Default);
}
}
private void LoopThroughSliders(GH_Document doc, List<IGH_Param> Inputs)
{
Inputs.ForEach(input =>
{
if (input.GetType() == typeof(GH_NumberSlider))
{
var r = new Random();
var slider = input as GH_NumberSlider;
decimal sliderMax = slider.Slider.Maximum;
decimal sliderMin = slider.Slider.Minimum;
double sliderMaxDouble = Convert.ToDouble(sliderMax);
double sliderMinDouble = Convert.ToDouble(sliderMin);
double mappedRand = MapValue(0, 1, sliderMinDouble, sliderMaxDouble, r.NextDouble());
//slider.Slider.RaiseEvents = false;
slider.Slider.Value = (decimal)mappedRand;
//slider.Slider.RaiseEvents = true;
}
});
runCount++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment