Hi! I am a beginner writing c# script and it takes me forever to figure out a simple function.
I would really appreciate for your input!
I wish to sort index numbers based on closest distance. As like the screenshot by using vanilla grasshopper components. However I wish to use ‘for’ loop and run this function automatically with c# script (because I do not know python) for further development.
I tried to write the script by myself but the quality is so shameful so I am not even dare to publish it here. The most difficult part was I do not know how to get the start/end point from the shortest line. I searched Rhinocommon API and when I use pt.PointAt(0) method, it takes point(0,0,0) not the starting point on the specific line.
Hope I made clear explanation. Thanks for your advice!!
BTW: For a given Point3d pStart = pList[index] and using a clone cpList = pList.ToList() … cpList = cpList.OrderBy(x=>x.DistanceTo(pStart)).ToList(); sorts the clone. Then foreach(Point3d p in cpList) int sortedIndex = pList.IndexOf( p )
it is so clean! previously I drew lines between points, made a double type list to store length, and then use if(value<min) function to compare all value blah blah blah… but it is so simple and neat by using sortedPts.OrderBy(x => x.DistanceTo(start)).ToList() function! hahaha!!!