Grasshopper

algorithmic modeling for Rhino

Adding input/output parameters using IGH_VariableParameterComponent

Dear David,

I have some problem with adding input params by dropdown menu.

I've checked this discussion: http://www.grasshopper3d.com/forum/topics/adding-input-output-param...

And I'v try to implement your solutions. But I found some bugs (in GH or caused by my code)

So I've create globally two params:

private IGH_Param sensRadiusParam;
private IGH_Param grayScaleParam;

and some static method to create new instance of this param (example) :

private static IGH_Param addSensRadiusParam()
{
IGH_Param param = new Param_Number()
{
Name = "Sensitivity Filter Radius",
NickName = "Sr",
Description = "",
Access = GH_ParamAccess.item
};
return param;
}

I'm registering three static Inputs, additional two should be optional: 

And in DropDown menu I'm calling this event:

private void MenuSensitivityFilter(Object Sender, EventArgs e)
{
oParam.UseSensitivityFiltering = !oParam.UseSensitivityFiltering;
if (oParam.UseSensitivityFiltering)
{
sensRadiusParam = addSensRadiusParam();
Params.RegisterInputParam(sensRadiusParam,3);
}
else
{
sensRadiusParam.RemoveAllSources();
Params.UnregisterInputParameter(sensRadiusParam, true);
}
this.ExpireSolution(true);
}

So creation of new inputs working great. Also destroying them is fine, but rest of the behaviour is corrupted...

For example, when one of the inputs is created, I cannot connect to it any already existing on canvas object (in my case slider). If I create new object or copy existing one it works. Maybe I need to redraw canvas?

Also removing and adding Inputs in any order cause some mess on canvas... Specially when I remove connected Input.

Here, for example I've created 2 output and remove one... 

As you can see, removed input param still exist somewhere... ( i can add connection between inputs slots as on picture, but when I release mouse button connection disappears, slider inheriting Input name and components get orange with warning (no data on input xxxx).. strange).

Sometimes it looks like input get connected with slider, but component warns me about "no data on input xxxxx" or slider is getting wrong name (from different parameter) 

Could you help me?

I'm attaching full cs file

Views: 2067

Attachments:

Replies to This Discussion

Not David, but here is some component I made a while ago. It has few ways of combining lists of guids (completely unimportant for you), and you can switch between them with the right-click menu. This either adds or removes the parameters. Takes care of serialization and also the Undo stack.

Attachments:

Try calling Params.OnParametersChanged() after you're done adding/removing stuff, and before ExpireSolution(true)

Oooo.. that was soooooo easy. I'm ashamed :)

Thank you both :)

PS. For what the "MutableNickName" is responsible for?

If you set it to false, users won't be able to rename a parameter any more. 

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service