Hide Input Parameter using Boolean

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)

1 Like

Ah I see. Yes that makes more sense to do it in component menu. Thanks a lot.