Grasshopper

algorithmic modeling for Rhino

The more I start to develop grasshopper plugins, the more I start to wonder what the correct way to handle different input structures is. For example, lets say I have a component with two inputs. How do I handle it if there is a item/item vs item/list vs list/item/ vs item/tree. Etc. etc.

All of the existing Grassopper components seem to handle these situations very gracefully. How do I make sure that my components do the same thing?

Thanks

Views: 918

Replies to This Discussion

Hi Ryan,

  1. Set the access of each input to either item, list or tree. The best place to do this is in RegisterInputParams, or -if you implement IGH_VariableParameterComponent- in VariableParameterMaintenance().
  2. Inside SolveInstance(), use the DA object and the appropriate GetX() method to retrieve your data. If an input parameter is set to item, then use DA.GetData(), if the input is set to list, then use DA.GetDataList().

The type of data you request is another decision you need to make. I usually ask for System.Double, System.Int32 and Rhino.Geometry.Brep instead of GH_Double, GH_Integer and GH_Brep as it makes my component code easier. The necessary conversions are handled by the DA object. It sometimes makes sense to get an IGH_Goo or IGH_GeometricGoo, but that's rare.

--

David Rutten

david@mcneel.com

Hello,

this is an old thread, but I have a similar question. I can't get an idea of how should I handle DataTrees inside plugins. Right now I have something like this:

            GH_Structure<IGH_Goo> boxInfo = null;
            if (!DA.GetDataTree<IGH_Goo>(0, out boxInfo)) return;

But it makes some problems later, because I have to cast types.

This code doesn't work however:


            DataTree<int> boxInfo = new DataTree<int>();

            DA.GetDataTree(0, ref boxInfo);


As I mentioned before, I can try to cast IGH_Goo to int later in code, but you mentioned that getting IGH_Goo rarely makes sense. What would be a good solution then?

Thank you in advance,
Krzysztof Nazar

Thanks for advice. Right now I'm good with

[some IGH_Goo instance].CastTo<int>(out [some integer variable])
...but wasn't sure if it's the right / efficent way.

I have to check out these "Solid principles"

Best,
Krzysztof

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