Grasshopper

algorithmic modeling for Rhino

Hallo David,

What is the best way to add a new complex parameter type e.g. a mesh or a graph to Grasshopper so that I do not lose time when parsing and that it will register with the type hint parameter...

Possible?

thx Richard

Views: 2678

Replies to This Discussion

Hi Richard,

you cannot add type hints to VB/C# components, there is currently no mechanism for that.

If that's not what you meant by 'type hint', then the steps required for adding your own parameter are:

  1. Create a type that implements IGH_Goo or derives from GH_Goo<T>. Usually the goo type wraps an existing type. For example, GH_Number wraps around System.Double. GH_Brep wraps around Rhino.Geometry.Brep. If you have a type called Graph which has all the fields/functionality of whatever your graph is about, then create a second type, call it GooGraph and derive it from GH_Goo<Graph>. The SDK documentation shows how to do this.
  2. Create a type that implements IGH_Param or which derives from GH_Param<GooGraph>. Call this class ParamGraph or something and make sure it has a unique ComponentID, icon etc. etc.
  3. Inside the RegisterInputParams and RegisterOutputParams methods on GH_Component, you can then call the pManager.AddParameter() method and pass it an instance of ParamGraph.

ps. Deriving from the abstract types is typically a better idea than implementing the interfaces from scratch.

pps. If you don't have the SDK documentation yet, get it now. You can download it via the Grasshopper help menu.

--

David Rutten

david@mcneel.com

Did go through the SDK Documentation, didn't help...

Lets assume that graph is an Interface will this also work with the Interface?

And further, assume that the class graphVertexList implements the interface graph and e.g. the class BFS inherits from graphVertexList, will I be able to access the functions of BFS in an other component when I pass it the way you suggested or can I only access the functionality of the interface Graph. 

Sorry for being a little complicated. I just spend about two month of work packing SpiderWeb into a library and now I have to rewrite the components. I figured that if I pass the information between components not as DataTrees of integers and doubles I could make the components work faster. As I don't want t spend another two months doing this I would like to start it the best way.

thx

Richard

p.s. if it helps I can send the .dll and a documentation of the Library

Hi David, I'm trying to do what you said, but at the last step when creating the parameter class I'm being returned an error.

This is the C# code:

class ParamNN_Options : GH_Param<GooNN_Options>
{
   public ParamNN_Options()
   {
    
   }
}

And this is the error returned:

Error 1 'GH_Param<GooNN_Options>' does not contain a constructor that takes 0 arguments 

GooNN_Options has a constructor with no arguments and the same for the class it inherits. Does it have something to do GH_Param? 

Merry Christmas and happy new year!

Your constructor for a child (derived) class should pass arguments to the constructor for the base class. GH_Param's constructor takes a GH_InstanceDescription where you supply the info about the param, so it should look like this:

class ParamNN_Options : GH_Param<GooNN_Options> 
{
   public ParamNN_Options() : base(new GH_InstanceDescription("Some Name","Some Nickname","Some Description","Some Category"))
   {
    
   }
}

Ok I see, now it works, thanks!

Anyway, now my Grasshopper component's output uses the GOONN_Options class, but in the C# code I?m supplying it with a NN_Options, thus gh returns me an exception..

How could I convert it?

What is a 'Panel'? Is it a class you have defined in one assembly? Is it a class you have defined in various assemblies? Is it a class that inherits from GH_Goo or implements IGH_Goo or IGH_GeometricGoo? Did yes, did you define casting methods?

I'll have to see some code to give any useful feedback.

Sorry David, I erroneously deleted the comment.
Anyway, I figured it out. There was just the overhead of creating a GH_Goo<T> and access the value through the Value field to operate on it.
Anyway, yes, the class is custom, and to help who will come, I just access the class through the Value field of the GH Wrapper class.

I have also seen the thread is quite old, I am interested in the addition of custom Type Hints into a C# component.
In the meanwhile, have you implemented any procedure to enable that?

No that was never changed. For custom data a type cast will be required.

Thanks David. i have found nothing in the SDK, but is there a shortcut to create a custom C# scriptable, without creating it from scratch?

I am inheriting from GH_ScriptInstance now, but without the documentation, I am a little disoriented there.

You'll spend a year of a life doing that (and not a fun year). Just use the system.object hint and perform a cast on line #1.

ahahahahha well, I'll make myself prepared with lots of crisps.

Would I bother you if I ask for a general guidelines set of such a procedure?

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