algorithmic modeling for Rhino


I am attempting to take a list(s) and append it to a datatree using AppendRange. The trouble I am having is the lists are not being added as individual branches. When I check the tree with PathCount the correct quantity of paths is returned. How is that possible?

I have also tried to add the individual elements (that would otherwise make up each list) one at a time to the same path. Basically using Append in the nested foreach loop rather than adding the elements to a list. This also did not work.

I've searched the forum for answers and can only seem to come up with bits and pieces of information that so far haven't helped find a solution. I suspect the solution is something obvious.

Code in question:

protected override void SolveInstance(IGH_DataAccess DA)
List<Brep> nodeList = new List<Brep>();
if (!DA.GetDataList(0, nodeList)) return;

List<GH_Line> lineList = new List<GH_Line>();
if (!DA.GetDataList(1, lineList)) return;

GH_Structure<IGH_GeometricGoo> tree = new GH_Structure<IGH_GeometricGoo>();

for (int i = 0; i < nodeList.Count; i++)
var bbox = nodeList[i].GetBoundingBox(true);

GH_Path path = new GH_Path(i);
List<GH_Line> branch = new List<GH_Line>();

foreach (GH_Line line in lineList)
if (line.Value.From.EpsilonEquals(bbox.Center, 0.001) || line.Value.To.EpsilonEquals(bbox.Center, 0.001))
tree.AppendRange(branch, path);

DA.SetDataList(0, tree);



Views: 315

Reply to This

Replies to This Discussion

No ideas on this one? Are the missing examples in the SDK,, for writing trees available anywhere?

Is there a particular reason you're using AppendRange rather than appending them one by one?

Thanks for the reply! Append did not work either. Using Append to add elements one by one or AppendRange to add them as lists result in a tree where PathCount returns the correct number of paths but the ultimate tree structure output in Grasshopper is a single path (single branch?) containing all of the elements.

You are definitely setting your output as a list, which is a problem: DA.SetDataList(0, tree); This should instead by DA.SetDataTree(0, tree); Plus, you'll need to make sure your GH_ParamAccess output is registered as a "tree", something like:

pManager.AddGeometryParameter("Output Geometry", "G", "Data tree of geometry", GH_ParamAccess.tree);

The output set to list was exactly the problem, don't know how I missed that. Seems so obvious now. Thanks man!






  • Add Photos
  • View All

© 2019   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service