Grasshopper

algorithmic modeling for Rhino

Hi all, 

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!

Cheers Dion

Views: 4886

Replies to This Discussion

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.

--

David Rutten

david@mcneel.com

Tirol, Austria

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();

param.AddNamedValue("option_1", 0);
param.AddNamedValue("option_2", 1);
param.AddNamedValue("option_3", 2);

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.
TargetInvocationException
}

Object: myComponent(level 2)
{
Unable to cast object of type 'Grasshopper.Kernel.Parameters.Param_Integer' to type 'System.Collections.Generic.IEnumerable`1[System.Int32]'.
InvalidCastException
}

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);

param.AddNamedValue("option_1", 0);
param.AddNamedValue("option_2", 1);
param.AddNamedValue("option_3", 2);

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?

Thanks!

Dion

pManager.AddIntegerParameter("Integer", "I", "input int", GH_ParamAccess.item);

Param_Integer param = pManager[0] as Param_Integer;

param.AddNamedValue("option_1", 0);

etc.

--

David Rutten

david@mcneel.com

Tirol, Austria

Yes, works like a charm!

Many thanks David!

Dion

Can this be done within a ghpython component? Anyone know of any examples of how?

Best

Jakob

No, you have to write your own parameter type for this, it cannot be done in any script components.

Alright, thanks for your reply David. Guess i better look into C#. There is no current way of doing this with Python at all, right?

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.


hacking services

WHO needs money??
need travel VISA??
PAYPAL AND BANK TRANSFER AVAILABLE
flight ticket available all destinations
ATM clone cards ready to ship all country
western union services back in the game
online shopping, ask me how it works
original FAKE or REAL id, dl, pp, skul docs available for all countries.

CONTACT ME NOW AT

watsap @0014242429194
icq @745215892
inbox @cleanhackdeals at gmail dot com

NB: dont waste your time to contact for fb, ig or twitter hack... few serious buyers needed

hacking services

WHO needs money??
need travel VISA??
PAYPAL AND BANK TRANSFER AVAILABLE
flight ticket available all destinations
ATM clone cards ready to ship all country
western union services back in the game
online shopping, ask me how it works
original FAKE or REAL id, dl, pp, skul docs available for all countries.

CONTACT ME NOW AT

watsap @0014242429194
icq @745215892
inbox @cleanhackdeals at gmail dot com

NB: dont waste your time to contact for fb, ig or twitter hack... few serious buyers needed

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service