Quantcast
Channel: Rhino Developer - McNeel Forum
Viewing all articles
Browse latest Browse all 8532

C# creating automatic sliders

$
0
0

@tognatta.aditya wrote:

Hey !
I am trying to create multiple sliders based based upon an integer input. I have modified James -ramden code:.
The problem is it works fine on the first attempt, but the number of sliders increases exponentially , I want them to erase the old sliders and generate new ones according to the integer input.
Here is my modified code.
private void RunScript(bool x, object y, int z, ref object A)
{

Random rnd = new Random();
int i = 0;

if(x)
{
  for(i = 0;i < z;i++)
  {
    //instantiate  new slider
    Grasshopper.Kernel.Special.GH_NumberSlider slid = new Grasshopper.Kernel.Special.GH_NumberSlider();
    slid.CreateAttributes(); //sets up default values, and makes sure your slider doesn't crash rhino

    //customise slider (position, ranges etc)
    int inputcount = this.Component.Params.Input[1].SourceCount;
    slid.Attributes.Pivot = new System.Drawing.PointF((float) this.Component.Attributes.DocObject.Attributes.Bounds.Left - slid.Attributes.Bounds.Width - 30, (float) this.Component.Params.Input[1].Attributes.Bounds.Y + inputcount * 30);
    slid.Slider.Maximum = 10;
    slid.Slider.Minimum = 0;
    slid.Slider.DecimalPlaces = 2;
    slid.SetSliderValue((decimal) (rnd.Next(1000) * 0.01));

    //Until now, the slider is a hypothetical object.
    // This command makes it 'real' and adds it to the canvas.
    GrasshopperDocument.AddObject(slid, false);

    //Connect the new slider to this component
    this.Component.Params.Input[1].AddSource(slid);
  }
}

}

Any help will be much appreciated

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 8532

Trending Articles