Grasshopper

algorithmic modeling for Rhino

Hi!

I'm trying to write for Grasshopper in C# a few custom components and a custom Data type that implements IGH_Goo. Now I'm passing this type of data to my own component with this code:

pManager.AddGenericParameter("Model", "Mod", "The models to add to this option as choices", GH_ParamAccess.item);

List<ConfigurableModel> models = new List<ConfigurableModel>();

if (!DA.GetDataList(0, models)) return;

It compiles and runs, but the last line of code is throwing a MissingMethodException: No parameterless constructor defined for this object.

Why might this happening? I would guess it has something to do with the custom data type that I have written, but I don't even know where to start looking for it and it's probably too long to paste all of it here.

Thanks,

Taavi

Views: 292

Replies to This Discussion

That error means that your ConfigurableModel doesn't have a constructor (i.e. new()) that is public and without parameters. To wit:

public ConfigurableModel()

{

   // Do whatever you need to do here to create a default, or maybe invalid ConfigurableModel.

}

Without such a constructor Grasshopper doesn't know how to create new instances of your type, which it needs in order to access the CastTo method, amongst other things.

Another problem is that you are accessing the parameter using GetDataList(), but your parameter has access of GH_ParamAccess.item. This will not work. You need to change the access to list, or use GetData().

If you've not already read it, I think the best forum post on how to create Custom Data type in GH is http://www.grasshopper3d.com/forum/topics/custom-data-type-gh-geome...

There is a really detailed example in it.

Cheers!

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