Hi, I am trying to change the number slider value dynamically. Following code is working with one dimensional array, which is xnew[]
:
private void RunScript(List<double> x, int nTimes, bool run, ref object A)
{
//based on code snippets from David Rutten and James Ramsden:
//http://james-ramsden.com/remotely-change-value-of-number-slider-grasshopper/
int n = x.Count;
if(run)
{
if((nTimes != minimum))
{
minimum = nTimes;
counter = nTimes;
}
//while(counter > 0){//time iteration, now it is controlled instead with the input nTimes
double[] x_new = new double[n];
var input = Component.Params.Input[0];//gets sliders in
for(int i = 0; i < n;i++)
{
Random rnd = new Random(Guid.NewGuid().GetHashCode());
x_new[i] = rnd.NextDouble();
var slider=input.Sources[i] as Grasshopper.Kernel.Special.GH_NumberSlider;
slider.SetSliderValue((decimal) x_new[i]);
slider.Slider.DrawControlBackground = true;
slider.Slider.DrawControlBorder = true;
slider.Slider.ControlEdgeColour = System.Drawing.Color.Blue;
slider.Slider.ControlBackColour = System.Drawing.Color.Aquamarine;
//slider.Slider.DecimalPlaces = 4;
}
InRun = run;
if(counter < 0){InRun = false;}
A = x_new;
if(InRun){GrasshopperDocument.ScheduleSolution(100, ScheduleCallback);}
//}
}
}
// <Custom additional code>
// <Custom additional code>
//private bool _run = false;
private int minimum = -1;
private int counter = -1;
private bool InRun = false;
private void ScheduleCallback(GH_Document document)
{
counter--;
Component.ExpireSolution(false);
}
However, I want to change the value of slider with two dimensional array, which requires one more loop (for using it in populated algorithms) Following code gives an idea about what I want to do, but not working properly:
private void RunScript(List<double> x, int nTimes, bool run, ref object A)
{
//based on code snippets from David Rutten and James Ramsden:
//http://james-ramsden.com/remotely-change-value-of-number-slider-grasshopper/
int n = x.Count; //parameter Size
int p = 5; //population size
if(run)
{
if((nTimes != minimum))
{
minimum = nTimes;
counter = nTimes;
}
double[,] x_new = new double[p, n];
var input = Component.Params.Input[0];//gets sliders in
for(int i = 0; i < p;i++)
{
for(int j = 0; j < n;j++)
{
Random rnd = new Random(Guid.NewGuid().GetHashCode());
x_new[i, j] = rnd.NextDouble();
var slider=input.Sources[j] as Grasshopper.Kernel.Special.GH_NumberSlider;//i_th slider
slider.SetSliderValue((decimal) x_new[i, j]);
slider.Slider.DrawControlBackground = true;
slider.Slider.DrawControlBorder = true;
slider.Slider.ControlEdgeColour = System.Drawing.Color.Blue;
slider.Slider.ControlBackColour = System.Drawing.Color.Aquamarine;
//slider.Slider.DecimalPlaces = 4;
}
}
InRun = run;
if(counter < 0){InRun = false;}
A = x_new;
if(InRun){GrasshopperDocument.ScheduleSolution(100, ScheduleCallback);}
//}
}
}
// <Custom additional code>
// <Custom additional code>
//private bool _run = false;
private int minimum = -1;
private int counter = -1;
private bool InRun = false;
private void ScheduleCallback(GH_Document document)
{
counter--;
Component.ExpireSolution(false);
}
Any hint is very much appreciated!
Cemre