//Code written by Luis Quinones @ [complicitMatter]
  //Feel free to use and modify the code in any way you want, please comment below with suggestions, ideas of any relevant throughts

  private void RunScript(Mesh meshIn, List<Point3d> attrPts, int cPCount, double vAmp, bool toggle, ref object C, ref object A)
    Rhino.Geometry.Collections.MeshVertexList vList = meshIn.Vertices; 
    Rhino.Geometry.Collections.MeshFaceList fList = meshIn.Faces;

    List<Point3f> vertToList = vList.ToList();
    List<Point3d> vertPtList = vertToList.ConvertAll(x => (Point3d) x); //convert vertexlist from point3f to point3d
    List<Point3d> vertPtDup = new List<Point3d>(vertPtList);

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

    foreach(Point3d pt in attrPts){ //go through each attractor point (creepers)

      for(int i = 0; i < cPCount; i++){ //for however many closestpoints you want each attractor to have

        int cIndex_A = Rhino.Collections.Point3dList.ClosestIndexInList(vertPtList, pt);

        Vector3d subVec = Vector3d.Subtract(new Vector3d(pt), new Vector3d(vertPtList[cIndex_A]));
        Vector3d mult = new Vector3d();
          mult = Vector3d.Multiply(subVec, vAmp); //if toggle is false amplify the vector by the user defined value
          double dist = pt.DistanceTo(vertPtList[cIndex_A]);
          mult = Vector3d.Multiply(subVec, dist); //if toggle is true then use the distance to the creeper pos 

        int moveIndex = vertPtDup.IndexOf(vertPtList[cIndex_A]); //get the index of the current closest point

        vList.SetVertex(moveIndex, Point3d.Add(mult, vertPtList[cIndex_A])); //set the mesh vertex at the specified index to the new location

        vertPtList.RemoveAt(cIndex_A); //remove the previous index from the vertex list to find the next closest point
    creeperMesh = meshIn;
    ptsOnMesh = vertAsPoint;
  • Share