Default input for pManager.AddGenericParameter()

script

(Shimpei) #1

Hi

I’m struggling with getting data from input.
I used my own .dll class and pmanager.AddGenericParameter() to get my datatype.
I want to add default data to my component but there is no way to do this in the method.
And also I want to avoid error message “input param failed to collect data” when there is not connection in input.
Here is related topics I found but I couldn’t reach to do that.

Is there anybody who know about how to do this?

Best,
Shimpei


#2

I want to add default data to my component but there is no way to do this in the method.

In register parameter:
param.SetPersistentData(defaultData);
But your parameter must inherit GH_PersistentParam instead of GH_Param.

And also I want to avoid error message “input param failed to collect data” when there is not connection in input.

In register parameter:
param.Optional = true;


(Shimpei) #3

Hi Dani_Abalde,
Thank you for the reply.

I couldn’t understand what you said because my knowledge is so poor…

For example, if I wrote this class and inputparams

                 public class example{
                    public int a;
                    public string b;

                    public example(int number, double value, string description){
                        a = number;
                        b = description;
                    }
                 }

                protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
                {           
                 pManager.AddGenericParameter("number", "num", "set num", GH_ParamAccess.list);
                 pManager.AddGenericParameter("string", "str", "set str", GH_ParamAccess.list);
                }

How should I script in Register to set PersistentData?
I apologize to bother you again.

Best
Shimpei


#4

Not sure, what you want to do exactly, do I understand correctly that you have created your own class and want to pass it around between components as a parameter? There is a well documented example for that in the Grasshopper Developer Guide (simple datatype + simple parameter).

Basically you need too write a wrapper type (e.g. ExampleGoo) which implements GH_Goo and a corresponding parameter ExampleParameter which implements GH_PersistentParam. Then you can access it in your component with pManager.AddParameter(new ExampleParameter()…).


(Shimpei) #5

Hi dsonntag,

Thank you for the reply!

Now I’m reading documents you suggested to improve my skill.
And, All I want to do is that to avoid error message.You can see picture I attached.

I can do without “DLOAD” and “MOMENT” on C# component on Grasshopper canvas, but I failed to do that in Visual Studio.
So, I thought that I should set default parameter to avoid this error message.


(David Rutten) #6

There’s a big difference between default data and optional parameters. You should always provide some default values if at all possible, even if just to show people what sort of value might be sensible.

Optional parameters will not prevent the component from running if they are empty. You can mark parameters optional like @Dani_Abalde said in RegisterInputParams:

pManager.RegisterSomeParameter("Name", "NickName", "Description", etc.)
pManager[0].Optional = true;