algorithmic modeling for Rhino
This is a continuation to the previous thread.
My original question was:
Are there other ways to determine/add/remove of inputs/outputs after the canvas is dragged onto the canvas? I was hoping in having a right-click checkbox menu to allow users to select what shows as output and what doesn't. I want to be able to achieve this without IGH_VariableParameterComponent().
Thanks!
Tags:
It is possible, but even then IGH_VariableParameterComponent (IGHVPC) is advised. The IGHVPC interface handles (de)serialization of variable parameters, which will be problematic without it. For example, imagine the following:
The best way to approach this is to implement IGHVPC, but implement it with empty methods. Always return False, don't do anything in the required functions. This will effectively hide the zooming UI, but it will still retain the added (de)serialization logic needed for saving and opening files.
To add or remove a parameter yourself, all you have to do is register or unregister it with the Params objects that is part of GH_Component. Note that you should not do this during solutions. It's ok to do it from event handlers such as mouse clicks.
An example of a method that adds an output parameter might look like this:
private void AddOutput()
{
Grasshopper.Kernel.Parameters.Param_Boolean param = new Grasshopper.Kernel.Parameters.Param_Boolean();param.NickName = "B";
param.Name = "Bool";
param.Description = "Boolean output";
param.Access = GH_ParamAccess.list;Params.RegisterOutputParam(param);
ExpireSolution(true);
}
--
David Rutten
david@mcneel.com
Several ways to solve it, really depends on what you'd rather do.
1. Create a different bool for each option:
private bool _showTime = true;
private bool _showTemp = true;
private bool _showDewP = true;
....
This is easy because you know the variables are always there. With an array you'd have to keep testing for null to be sure not to cause a NullReferenceException.
2. Create an array of bools. Least amount of typing.
3. Create an enumeration with the Flags option set to store the state:
[Flags]
private enum OutputState
{
ShowNone = 0,
ShowTime = 1,
ShowTemp = 2,
ShowDewP = 4,
ShowWind = 8,
...
ShowAll = 127
}
private OutputState _state = OutputState.ShowAll;
4. There's other ways as well, but I'd pick one of these three.
--
David Rutten
david@mcneel.com
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by