Grasshopper

algorithmic modeling for Rhino

How to manully register parameters when writing a grasshopper component?

Hi,

The Grasshopper SDK doc highly recommends to register parameters via pManager, but what should I do if I want to register a parameter with a type like List<Rhino.Geometry.NurbsCurve> or List<double> ? Do I have to register these kind of data manually? or, if I want to register an output parameter,  Is it possible to register it as "object" type just like what C# components automatically do with the output parameters? Would there be any speed loss if just register the output as "object" type?

 

Thanks!

-Jerome

Views: 1123

Replies to This Discussion

Hi Jerome,

 

You can register lists of doubles in this format:

pManager.Register_DoubleParam("Name", "Label on Component", "Description", GH_ParamAccess.list);

 

Note the GH_ParamAccess.List part. To read or write these parameters you need to use the IGH_DataAccess.GetDataList and .SetDataList instead of the usual .GetData and .SetData functions.

 

If you need to output any arbitrary type, you can use

pManager.Register_GenericParam(etc);

 

Usually before outputting a generic parameter I warp it first in a GH_ObjectWrapper, which I unwrap on my other components that expect them. 

 

I'd need to know a little bit more about what you indeed to do to offer any more assistance.

 

Cheers,

Chris

Thanks, Chris

What I am doing actually is an idea of using classes freely. It seems that one C# component has to be a single class, and I can only create nested classes. I know I could define classes in VS and reference those dlls in C# component, I thought it would be more helpful if I just make a component all in VS. I love the intellisence provided by VS and I know I would not be able to detect errors that generated by Rhino clearly in VS, but I know I would get more help on C#. I could not find a perfect solution for this, so I decided to try to make a component in VS and experience the pros and cons.

Does .net 4.0 the framework I should choose when I create a component in VS?

I couldn't find enough resources to help me out when I create a component in VS, I just have one Grasshopper SDK doc downloaded via Grasshopper Help menu and there  are just some really basic tutorials to start from, so, actually, I cannot fully understand what are GH_ObjectWrapper, and how and when to use them.

 

Thanks,

-Jerome

Hi Jerome,

 

Giulio Piacentino has an excellent tutorial video on starting a C# component for grasshopper scratch, which is here: Video Tutorial

 

That should help you get started with the basics, there isn't a lot of documentation out there at the moment.

 

You should set your 'Target framework' in your project properties to '.Net Framework 3.5'.

 

I'm not sure if it will be helpful or just more confusing, but I've attached the source code to a component I wrote for the SPM Vector Components set. It's a simple component that takes in a vector and a boolean and outputs a custom settings object as a GenericParam.

 

I'm not qutie the best at explaining this part, but the output of this component is meant to be passed into another of my components, which accepts it as a GenericParam, and then unwraps the GH_ObjectWrapper. I hope this won't be too confusing to follow, but I've pasted in some sample code below on how this is handled:

 

// inside the component which receives the output of the component I attached to this forum post

protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)       

{

pManager.Register_GenericParam("Dynamics", "D", "Dynamics Input");

}

 

protected override void SolveInstance(IGH_DataAccess DA)

{

// read in the wrapped object

 

    var dynamicWrapped = new GH_ObjectWrapper();

    DA.GetData(0, ref dynamicWrapped)

 

    // unwrap the object by casting its value to the type you expect

    var dynamicObj = dynamicWrapped.Value as IDynamic

 

    // now use dynamicObj as you would any other object

}

Attachments:

Thanks, Chris

The video tutorial and your example really helps me a lot.

I can't ask any more questions on this before following these with my own practice for sometime.

 

Thank you!

-Jerome

Chris, sorry to bother,

I found that no overloads of pManager.Register_DoubleParam that takes four arguments, which means that

pManager.Register_DoubleParam("Name", "Label on Component", "Description", GH_ParamAccess.list);   may not be the correct syntax to declare a list.

 

Thanks,

-Jerome

These are the overloads for Register_DoubleParam:

 

Public Sub Register_DoubleParam(ByVal name As String, ByVal nickname As String, ByVal description As String)

 

Public Sub Register_DoubleParam(ByVal name As String, ByVal nickname As String, ByVal description As String, ByVal access As GH_ParamAccess)

 

Public Sub Register_DoubleParam(ByVal name As String, ByVal nickname As String, ByVal description As String, ByVal [default] As Double)

 

Public Sub Register_DoubleParam(ByVal name As String, ByVal nickname As String, ByVal description As String, ByVal [default] As Double, ByVal access As GH_ParamAccess)

 

the bold one is the one you want.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks, David

Thanks David,

I tried again but I might did something wrong in the first place.

I am referencing GH_IO.dll, Grasshopper.dll and Rhinocommon.dll with copy local set to false.

I am using May 31st build of Rhino 5.0 and Grasshopper 0.8.0010.

My VS project based on the .net framework 3.5.

 

Thanks,

Jerome

You are doing this in RegisterOutputParams(), not RegisterInputParams(). Output parameters do not have access flags assigned to them as this information can be inferred at runtime.

 

If you use DA.SetData() the parameter will act like GH_PAramAccess.item, if you use DA.SetDataList() then it will act like GH_ParamAccess.list.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks! David

Thank you!

 

-Jerome

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service