Grasshopper

algorithmic modeling for Rhino

Hello,

I was trying to sort a list of points first in the Y direction, then in the X direction and then in the Z direction, all from the smallest to the biggest. I know there is a Sort List component in Grasshopper but I was trying to do this in a script.
Unless there is a way to access the sort component inside the script?

I'm very much new in scripting/VB and this may very well be a very silly doubt but I was hopping someone could  help me.

Thanks in advance.

Views: 354

Replies to This Discussion

Hi Carlos,

usually you put all the points into a List<Point3d>, then you use the Sort() method on that list while providing your own Comparer<Point3d> or Comparison<Point3d>. This can be either a class or a method delegate. For example:

  List<Point3d> points = new List<Point3d>();

  // Fill up list with points.

  points.Sort(new xyzSorter());

  ......

  private class xyzSorter : IComparer<Point3d>

  {

      int IComparer.Compare(Point3d A, Point3d B)

      {

         int rc = 0;

         rc = A.X.CompareTo(B.X);

         if (rc != 0) return rc;

         rc = A.Y.CompareTo(B.Y);

         if (rc != 0) return rc;

         rc = A.Z.CompareTo(B.Z);

         if (rc != 0) return rc;

         return rc;

      }

  }

--

David Rutten

david@mcneel.com

Thanks for the help David!

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2025   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service