Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@arefin86
Last active April 4, 2019 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arefin86/468ddbc945820d78439c9b5aa16311b2 to your computer and use it in GitHub Desktop.
Save arefin86/468ddbc945820d78439c9b5aa16311b2 to your computer and use it in GitHub Desktop.
// 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