Grasshopper

algorithmic modeling for Rhino

Hi all,

I have a simple problem:

I want to get the .Min and .Max value of various lists. I Already get the value but one for every list but I would just need one value out of all.

Same as flatten the bounds component in GH. I think .ToList is the right way but dont get it to work.

I think I could get the value using a tree instead of a list and flatten the tree,but maybe I am totally wrong and someone can offer a nicer and claener way to reach this.

Ah, and yes flattening the points input would surely work but for the sake of learning it would be nice see another way

thanks in advance!

Views: 960

Attachments:

Replies to This Discussion

Using tree access is one way to go (I think the best way).

private void RunScript(DataTree<Point3d> pts, Curve crv, Interval Target, ref object A, ref object B, ref object C)
{
  Component.Message = "CrvClosestPt";

  double min = double.MaxValue;
  double max = double.MinValue;
  List<double> distances = new List<double>();

  foreach (Point3d point in pts.AllData())
  {
    double parameter;
    crv.ClosestPoint(point, out parameter);
    Point3d cp = crv.PointAt(parameter);
    double localDistance = cp.DistanceTo(point);

    distances.Add(localDistance);
    min = Math.Min(min, localDistance);
    max = Math.Max(max, localDistance);
  }

  A = distances;
  B = min;
  C = max;
}

It gets a bit more complicated if you want your collection of distances to also be a tree, rather than just a flat list.

Another approach would be to use the BeforeRunScript and AfterRunScript methods to aggregate min and max values throughout the entire process.

Nice! Thanks a lot, for the moment a flat list is enough!

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