Grasshopper

algorithmic modeling for Rhino

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!

Views: 1147

Replies to This Discussion

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.

Hi David,

Thanks for your help with this. I tried that out and it didn't quite do what I'm looking for. Basically what I'm trying to do is this: for the component in the attached image, inputs 1,2,3,4 would be constant, but I would like to add optional parameters after number 4 that would adhere to a naming convention like "R1, R2, etc". I tried applying your code to the VariableParameterMaintenance but changed the for loop to 

for(int i = 4; i<10; i++)

in that I want to start the change in naming at index 4, and continue on to some number(10 in this case). This kind of works, however the component doesn't refresh when I click the "+". It only refreshes if I change something about the component like the name, or turn it on or off. 

Am I on the right track? Thanks again, I'm pretty new at this.

Attachments:

Can you post the minimal code needed to replicate the problem?

Sure, at the moment it's basically the sample code that comes with the .gha assembly template. i'm just trying to get the variable inputs to behave the way i want before going any further. Thanks!

Attachments:

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