Grasshopper

algorithmic modeling for Rhino

HEllo all,

I am trying to work my way around trees in Visual Studio Express 2013 (C#).

I have this to work in the C# component within Grasshopper but can't get it to work in Visual Studio. I think because I am missing the syntax.

QUESTION: Let's say I have a tree as in the attached image. I would like to access that in Visual Studio and then loop through each branch and path.

This is my attempt:

RegisterInputParams:

pManager.AddGenericParameter("Curves tree", "C", "tree test", GH_ParamAccess.tree);

RegisterOutputParams:

pManager.Register_CurveParam("Tree", "T", "Tree test", GH_ParamAccess.tree);

SolveInstance:

GH_StructurePath cc = new GH_StructurePath();

if (!DA.GetDataTree(1, cc)) return; //Gives me an error

//Here I would like to loop over each branch and each path

Thanks for your help!

Views: 1764

Attachments:

Replies to This Discussion

I got the first part to work.

REVISIONS:

SolveInstance:

Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Curve> ccc = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Curve>();

if (!DA.GetDataTree(1, out ccc)) return; //Error here is solved

//Any hint on how to loop overt he tree would be appreciated

Thank you!

Attached is the error I am getting now.

Although the error is probably due to my use of IGH_goo I am also copying the piece of code that shows how I am looping:

Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.IGH_Goo> c1 = new Grasshopper.Kernel.Data.GH_Structure<IGH_Goo>();


if (!DA.GetDataTree(1, out c1)) return;

for (int i = 0; i < c1.Branches.Count; i++)
{
    for (int j = 0; j < c1.Branches[i].Count; j++)
    {
        list.Add(i.ToString());
    }

}

Any reference on when to use GH_ vs IGH_goo would be really apprectiated.

Thank you.

Attachments:

This is my attempt using GH_ where I get a similar error (see attached):

Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Curve> ccc = new Grasshopper.Kernel.Data.GH_Structure<Grasshopper.Kernel.Types.GH_Curve>();

if (!DA.GetDataTree(1, out ccc)) return;

for (int i = 0; i < ccc.Branches.Count; i++)
{
for (int j = 0; j < ccc.Branches[i].Count; j++)
{
list.Add(i.ToString());
}
}

Attachments:

solved.

my bad...output was of type curve and I was outputting a List<string>

I revised the outupt this way:

pManager.Register_StringParam("Tree", "T", "Tree test", GH_ParamAccess.list);

also I wasn't using GH_Structure and found a good explanation and solution here: http://www.grasshopper3d.com/forum/topics/datatree-of-object-gh-str...

sorry for thinking out loud on the forum.

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service