Variable Parameter Component Nicknames

I'm just getting started writing custom components in Visual studio. I'm just starting to work out and understand how the variable parameter components work, and I'm curious about something. I was looking at this thread and i've got it adding parameters. In the command InventUniqueNickname it asks for a string of allowable names. In the code in the referenced thread, that string is "ABCDEFGHIJKL....etc. which results in new inputs being A, B, C etc. My question is how can I make those values be something like "R1, R2, R3, R4"? the code currently looks like this:

IGH_Param IGH_VariableParameterComponent.CreateParameter(GH_ParameterSide side, int index)
{
Grasshopper.Kernel.Parameters.Param_Number param = new Grasshopper.Kernel.Parameters.Param_Number();

param.Name = GH_ComponentParamServer.InventUniqueNickname("ABCDEFGHIJKL", Params.Input);
param.NickName = param.Name;
param.Description = "Param" + (Params.Input.Count + 1);
param.SetPersistentData(0.0);

return param;

Thanks!

  • up

    David Rutten

    You can't use the InventUniqueNickname to generate names like "R1", "R2" etc. You'll have to write your own name generator.

    If your inputs are always named R1 to Rn from top to bottom, and the user cannot change this, then you can set the MutableNickName peoprty to false on each input and then assign all names in a loop inside VariableParameterMaintenance().

    for (int i = 0; i < Params.Input.Count; i++)

    {

      Params.Input[i].MutableNickname = false;

      Params.Input[i].NickName = "R" + (i+1).ToString();

    }

    If you just want to assign a pro tem nickname that the user is allowed to change, then you'll have to replace the InventUniqueNickname() call with a method of your own devising.

    3