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_入力したBooleanToggleの初期値を設定する
private void RunScript(bool x, 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)
{
switch(i)
{
case 0:
SetBooleanToggle(i, "Super Riser", false);
break;
}
}
}
}
//AfterRunScript内でBooleanToggleを操作するためのメソッド
public void SetBooleanToggle(
int rowNumber, string name, bool defaultParam)
{
//サンプルデータとして入力が想定されるコンポーネントを
//BooleanToggleと決めつけた書き方(他のタイプだとエラーになる)
ghCPS = this.Component.Params;
var boolToggle = (Grasshopper.Kernel.Special.GH_BooleanToggle)
ghCPS.Input[rowNumber].Sources[0];
//BooleanToggleがデフォルトの名前を持っている場合に書き換えを実行する
//ユーザーが変更できるNickNameを判定には使わない
if(boolToggle.Name != name)
{
boolToggle.Name = name;
boolToggle.NickName = name;
boolToggle.ExpireSolution(true);
}
}
// </Custom additional code>
}
@saitohiroaki1122

This comment has been minimized.

Copy link
Owner Author

@saitohiroaki1122 saitohiroaki1122 commented Jan 17, 2018

setbooleantoggle

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