algorithmic modeling for Rhino
I am pretty sure there is a simple answer to this question, but I can't seem to find it in any of the posts.
I am making a few custom c# components and I would like to create an input parameter that displays a list of options for the user to pick from as input.
Basically the input should present a small drop down menu with values to pick from like the construction shown below with a value list that returns an integer to the input based on the chosen option, so in other words I would like to integrate this value list component in the input parameter itself.
I have been looking in the GH_Component.GH_InputParamManager options but all these options give single values, lists or trees, and only show context menu's based on the type (like boolean input has a drop down menu for true/false).
So I was looking at the overriding methods for AppendAdditionalComponentMenuItems but here I can only set a list for the menu of the component itself and not a specific input param.
Do I need to somehow access the GH_ValueList methods in RegisterInputParams to do this?
Any help, or reference to older posts/ Grasshopper SDK would be great!
Thanks in advance!
Param_Integer allows you to specify named values. You can use this to provide a list of constants to the user:
Dim param As Param_Integer = getanintegerparameterfromsomewhere()
param.AddNamedValue("Option 1", 0)
param.AddNamedValue("Option 2", 1)
param.AddNamedValue("Option 3", 2)
It's probably best to put this code in the RegisterInputParameters method.
Hi David, thanks for the quick response!
I looked at the your code but I cannot seem to get it to work as an input parameter.
I tried inside the RegisterInputParams(GH_Component.GH_InputParamManager pManager) method, to cast the Param_Integer 'param' as a default value for the AddIntegerParameter method like so:
Param_Integer param = new Param_Integer();
pManager.AddIntegerParameter("Integer", "I", "input int", GH_ParamAccess.item,(int)param);
Trying to convert it directly to an integer like (int)param troughs the following error:
Error 1 Cannot convert type 'Grasshopper.Kernel.Parameters.Param_Integer' to 'int'
Trying to use either Convert.ToInt32(param) or (IEnumerable<int>)param both builds but upon loading the plugin give me Loading Errors:
Object: myComponent(level 1)
Exception has been thrown by the target of an invocation.
Object: myComponent(level 2)
Unable to cast object of type 'Grasshopper.Kernel.Parameters.Param_Integer' to type 'System.Collections.Generic.IEnumerable`1[System.Int32]'.
Then I tried the other way around to cast the int to Param_Integer like so:
Param_Integer param = (Param_Integer)pManager.AddIntegerParameter("Input", "I", "List input", GH_ParamAccess.item);
And consistently this gives me the same error but the other way around:
Error 1 Cannot convert type 'int' to 'Grasshopper.Kernel.Parameters.Param_Integer'
I feel like I am looking at this all wrong, any suggestions?
pManager.AddIntegerParameter("Integer", "I", "input int", GH_ParamAccess.item);
Param_Integer param = pManager as Param_Integer;
No, you have to write your own parameter type for this, it cannot be done in any script components.
The script components do not use Integer inputs, which is the only type that supports this by default. So you'll have to either create a custom component in Visual Studio which uses Integer inputs, or create an entirely new type from scratch. Neither is possible in C# scripting, and I assume it isn't possible in Python scripting either.
© 2023 Created by Scott Davidson. Powered by