Grasshopper

algorithmic modeling for Rhino

Hi,

I am trying to play and understand Custom Data Type.

I inherited Custom Data and Param from GH_Goo<object>, evrything works fine with non geometric data.

Now I am working on custom geometric data type inherited from GH_GeometricGoo<object>...I think it's going to work even if I didn't really tried - I still need to complete my class with overrided method like GetBoundingBox, Morph, Transform...(see enclosed for those that would be interrested).

But now that I am almost comfortable with custom Data in Grashopper, I am wondering about a few things...

Let's say I have a Custom component that allows to create a boat shell  for example.

As inputs of my "CreateBoatShell" component I have standard Data type like string, double or rhino geometries..

As output I want my Custom Data Type BoatShell.

So I cook inside my component, creating my custom data class Data_BoatShell, my custom Parameter Param_BoatShell but then I don't know from which Grasshopper type I have to inherit my BoatShell class. GH_Goo<object> or GH_GeometriGoo<object> ??

My Boat class has some geometry data like curve, brep or wahtever, but also non geometric data like string, double,..

What is the trick in such situation ?

thx

Views: 3867

Attachments:

Replies to This Discussion

Hi raf,

both IGH_Goo and IGH_GeometricGoo should be considered to be wrapping classes around your data. At least, that's how they were designed to work. Therefore is makes little sense to use GH_Goo<object> or GH_GeometricGoo<object>. My advice is to put all your data specific code into a custom class and call it -say- BoatShell. This class does not need to derive from anything or implement any interface, though of course it can:

public class BoatShell

{

  private double m_width;

  private double m_length;

  private Brep m_shape;

  private Curve m_waterLine;

  //add whatever constructors, methods and properties make sense.

}

Then, once you have your BoatShell class, you wrap it up into whatever goo best suits you. In this case, since there are geometric aspects to your data that should probably be drawn in the viewport, you should use GH_GeometricGoo:

public class BoatShellGoo : GH_GeometricGoo<BoatShell>

{

  //...

}

Here you will need to implement all the required methods and properties, and a lot of those should probably just directly call similar methods on the BoatShell class, just to make sure the functionality is widely available. Especially important are the casting methods, you must implement those (have a look at the SDK helpfile to see some examples of this). 

If you post some C# code that defines your actual data, i.e. the Boatshell class, I can help you out writing the GH_GeometricGoo wrapper for it.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hi David,

ok understood..I need some time to make some test, then I will probably come back to you.

Thanks again for your help.

Hi David,

well I have some issue with my custom parameter. 

Error 1 The type 'WIP.BoatShell' cannot be used as type parameter 'T' in the generic type or method 'Grasshopper.Kernel.GH_Param<T>'. There is no implicit reference conversion from 'WIP.BoatShell' to 'Grasshopper.Kernel.Types.IGH_Goo'. C:\Users\WIP\Custom Data Types\Boat.cs

I am not really sure about what method to override in my custom parameter. I guess Write and Read serialization method, but I am not sure...and also not very comfortable with...

Attached is my Boatshell class for test. If you can have a look and help I would really appreciate.

Thanks.

raf

Attachments:

See if the attached makes any sense. I made quite a few changes and relocations.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Attachments:

Hi David,

That's really great, your code helped a lot. Things are clearer now.

Thanks so much !

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