Grasshopper

algorithmic modeling for Rhino

Hello all,

For debugging purposes, I'm trying to assign default values for input parameters in a component I'm writing. The parameters are generic and I didn't find a way to do so.

I'm adding the code itself(SolveStructure) and a code for the structures construction(Vectors)

Thank you

Views: 2288

Attachments:

Replies to This Discussion

Hi Roey, you can write something like this:

pManager.AddGenericParameter("", "", "", GH_ParamAccess..., YOUR DEFAULT VALUE)

that's what I usually do.

in this case, the generic parameters are structures of 8 fields. how do I assign values for each field using what you wrote?

Hi Roey,

your data types do not derive from IGH_Goo, so you cannot put them in parameters. You have to wrap them up first inside GH_ObjectWrapper, or if you want to do it properly you can provide specific GH_Goo derived types for them.

May I also suggest you make all your structs immutable (if you want mutable data, uses classes instead of structs), and do not use abbreviations for variables and fields. You may remember today what it all means, but when you come back to this code one year from now, it'll be hard to figure out what e, a, i, l, no, val, and loc actually mean.

See attached file. It properly encapsulates private member fields, it makes all structs immutable, and it assign default values to the input parameters inside RegisterInputParams.

Attachments:

Thanks for the quick help.

and also for the enlightening remarks:)))

I have another question now.

If I want to access the parameters of "member" i get an error that this is readonly and I can't change it. for example, in the code you uploaded, try to assign "c" to member.L

Yes, that's what immutable means. Once a struct has been constructed, it can no longer be changed. You have to make a new struct if you want a different one. You could also add methods on the struct that allow you to change one of the fields.

public MyStruct SetPropertX(Type newX)
{
return new MyStruct(newX, _y, _z);
}

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service