Skip to content

Instantly share code, notes, and snippets.

@saitohiroaki1122
Last active Jan 17, 2018
Embed
What would you like to do?
GH C# Component tips_入力したNumberSliderの初期値を設定する
private void RunScript(double x, double y, ref object A)
{
}
// <Custom additional code>
GH_ComponentParamServer ghCPS;
public override void AfterRunScript()
{
ghCPS = this.Component.Params;
for(int i = 0; i < ghCPS.Input.Count; i++)
{
if(ghCPS.Input[i].SourceCount != 0)
{
Interval range;
switch(i)
{
case 0:
range = new Interval(0, 150);
SetNumberSlider(
i, "C-Value(C-Value Mode)", range, 90, 2);
break;
case 1:
range = new Interval(0, 1000);
SetNumberSlider(
i, "Row Height(Fixed Mode)", range, 230, 1);
break;
}
}
}
}
//AfterRunScript内でNumberSliderを操作するためのメソッド
public void SetNumberSlider(int rowNumber, string name,
Interval range, double defaultItem, int decimalPlaces)
{
//コンポーネントのパラメーター情報を取得する
ghCPS = this.Component.Params;
//サンプルデータとして入力が想定されるコンポーネントを
//NumberSliderと決めつけた書き方(他のタイプだとエラーになる)
var numSlider = (Grasshopper.Kernel.Special.GH_NumberSlider)
ghCPS.Input[rowNumber].Sources[0];
//NumberSliderがデフォルトの名前を持っている場合に書き換えを実行する
//ユーザーが変更できるNickNameを判定には使わない
if(numSlider.Name != name)
{
numSlider.Name = name;
numSlider.NickName = name;
numSlider.Slider.Minimum = (decimal) range.Min;
numSlider.Slider.Maximum = (decimal) range.Max;
numSlider.Slider.Value = (decimal) defaultItem;
numSlider.Slider.DecimalPlaces = decimalPlaces;
//NumberSliderの場合、ExpireSolutionはなくても大丈夫みたい
//numSlider.ExpireSolution(true);
}
}
// </Custom additional code>
@saitohiroaki1122

This comment has been minimized.

Copy link
Owner Author

@saitohiroaki1122 saitohiroaki1122 commented Jan 17, 2018

setnumberslider

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment