public static GH_NumberSlider CreateNumbersilder(string name, decimal min, decimal max, int precision = 0, int length = 174) { var nS = new GH_NumberSlider(); nS.ClearData(); //Naming nS.Name = name; nS.NickName = name; nS.Slider.Minimum = min; nS.Slider.Maximum = max; nS.Slider.DecimalPlaces = Axis.Util.LimitToRange(precision, 0, 12); if (precision == 0) { nS.Slider.Type = Grasshopper.GUI.Base.GH_SliderAccuracy.Integer; } else { nS.Slider.Type = Grasshopper.GUI.Base.GH_SliderAccuracy.Float; } nS.CreateAttributes(); var bounds = nS.Attributes.Bounds; bounds.Width = length; nS.Attributes.Bounds = bounds; nS.SetSliderValue(min); return(nS); }
private IGH_Param CreateIntegerSlider(int d) { var slider = new GH_NumberSlider(); slider.CreateAttributes(); // setup the slider according to the grid // each slider account for one grid dimension var t0 = ghGrid.Value.Intervals[d].T0; var t1 = ghGrid.Value.Intervals[d].T1; slider.Slider.Type = Grasshopper.GUI.Base.GH_SliderAccuracy.Integer; slider.Slider.Minimum = (decimal)t0; slider.Slider.Maximum = (decimal)t1 - 1; slider.SetSliderValue((decimal)(0.5 * (t0 + t1))); return(slider); }
//Methods //Automatically add a slider to the canvas void addWeightSlider(bool addSlider) { if (addSlider) { //Instantiate new slider GH_NumberSlider slider = new GH_NumberSlider(); slider.CreateAttributes(); //set to default values //Customisation of values int inputCount = this.Params.Input[1].SourceCount; //count the number of connected inputs slider.Attributes.Pivot = new PointF((float)this.Attributes.DocObject.Attributes.Bounds.Left - slider.Attributes.Bounds.Width - 30, (float)this.Params.Input[1].Attributes.Bounds.Y + inputCount * 30); slider.Slider.Minimum = -1; slider.Slider.Maximum = 1; slider.Slider.DecimalPlaces = 2; slider.SetSliderValue((decimal)0.00); slider.NickName = String.Format("w{0}", inputCount); //Add the slider to the canvas OnPingDocument().AddObject(slider, false); this.Params.Input[1].AddSource(slider); } }