Question
I want to control the show/hide inputParams in the component for user using a boolean toggle
There is function called GH_InputParamManager.HideParameter Method
How do we invoke this method with a boolean toggle within the component
Question
I want to control the show/hide inputParams in the component for user using a boolean toggle
There is function called GH_InputParamManager.HideParameter Method
How do we invoke this method with a boolean toggle within the component
It’s possible but why not add an item to the component menu? The event handler for this menu item runs outside of a solution, so it’s safe to modify your component layout then.
Menu:
public class Dynamic01 : GH_Component, IGH_VariableParameterComponent
{
public bool Show = false;
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddNumberParameter("A", "A", "A", GH_ParamAccess.item, 0);
pManager.AddNumberParameter("B", "B", "B", GH_ParamAccess.item, 1);
}
public bool CanInsertParameter(GH_ParameterSide side, int index) { return false; }
public bool CanRemoveParameter(GH_ParameterSide side, int index) { return false; }
public IGH_Param CreateParameter(GH_ParameterSide side, int index)
{
return new Param_Number
{
Name = "C",
NickName = "C",
Description = "C",
Access = GH_ParamAccess.item,
Optional = true
};
}
public bool DestroyParameter(GH_ParameterSide side, int index) { return true; }
public void VariableParameterMaintenance()
{
if (Show)
{
if (Params.Input.Count == 3) return;
Params.RegisterInputParam(CreateParameter(GH_ParameterSide.Input, 2));
}
else
{
if (Params.Input.Count != 3) return;
Params.Input[2].Sources.Clear();
Params.UnregisterInputParameter(Params.Input[2]);
}
}
protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown menu)
{
Menu_AppendItem(menu, "Show", Menu_Show_Clicked, true, Show);
}
private void Menu_Show_Clicked(object sender, EventArgs e)
{
Show = !Show;
VariableParameterMaintenance();
Params.OnParametersChanged();
ExpireSolution(true);
}
//...
}
Input:
public class Dynamic02 : GH_Component, IGH_VariableParameterComponent
{
public bool Show = false;
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddNumberParameter("A", "A", "A", GH_ParamAccess.item, 0);
pManager.AddNumberParameter("B", "B", "B", GH_ParamAccess.item, 1);
pManager.AddBooleanParameter("Show", "Show", "Show", GH_ParamAccess.item, false);
pManager[0].Optional = true;
pManager[1].Optional = true;
}
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager) { }
protected override void SolveInstance(IGH_DataAccess DA)
{
DA.GetData(2, ref Show);
}
protected override void AfterSolveInstance()
{
VariableParameterMaintenance();
Params.OnParametersChanged();
}
public bool CanInsertParameter(GH_ParameterSide side, int index) { return false; }
public bool CanRemoveParameter(GH_ParameterSide side, int index) { return false; }
public IGH_Param CreateParameter(GH_ParameterSide side, int index)
{
return new Param_Number
{
Name = "C", NickName = "C", Description = "C", Access = GH_ParamAccess.item, Optional = true
};
}
public bool DestroyParameter(GH_ParameterSide side, int index) { return true; }
public void VariableParameterMaintenance()
{
if (Show)
{
if (Params.Input.Count == 4) return;
Params.RegisterInputParam(CreateParameter(GH_ParameterSide.Input, 3));
}
else
{
if (Params.Input.Count != 4) return;
Params.Input[3].Sources.Clear();
Params.UnregisterInputParameter(Params.Input[3]);
}
}
//...
}
Dynamic.zip (31.4 KB) (Source)
Ah I see. Yes that makes more sense to do it in component menu. Thanks a lot.
Thanks for the example. I’m getting the wire to nowhere though.
I passed true
to the UnregisterOutputParameter
method’s isolate
argument. Didn’t work.
using System.Linq;
//...
protected override void AfterSolveInstance()
{
VariableParameterMaintenance();
base.AfterSolveInstance();
}
// ...
public void VariableParameterMaintenance()
{
// ...
while (Params.Input.Count>1)
{
Params.Input.Last().Sources.Clear();
Params.UnregisterInputParameter(Params.Input.Last(), true);
}
while (Params.Output.Count>1)
{
Params.Output.Last().Recipients.Clear();
Params.UnregisterOutputParameter(Params.Output.Last(), true);
}
Params.OnParametersChanged();
return;
}
// ...
I think it might be that I cleared the list of recipients before unregistering but without clearing, downstream components would expire during solution.
@Mahdiyar How do I set and reference the default value of the c input?
public IGH_Param CreateParameter(GH_ParameterSide side, int index)
{
var param = new Param_Number
{
Name = "C",
NickName = "C",
Description = "C",
Access = GH_ParamAccess.item,
};
param.AddVolatileData(new GH_Path(0), 0, 100);
return param;
}
Dynamic.zip (35.3 KB)
Thank you @Mahdiyar there is just the issue, if I delete the input (slider) after connecting to the component, it doesn’t return the default value. I get the warning message “Input failed to collect data”. I’m using the standart IGH_DataAcess DA
if (Params.Input.Count ==)
{
if (!DA.GetData(,ref)) return;
}