# Evaluate each successive point y value and cull if greater than previous?

Hi everyone,

I am a beginner to python and coding in general, and I was wondering how one could evaluate the y value of a point comparing it to its previous on the list and if greater than the previous eliminate it. The main goal would be this one:

Thanks for any info.

Perhaps something like the following? Let me know if it’s not clear…

``````import rhinoscriptsyntax as rs

pl=rs.GetObject("Select a polyline",4,True)
#check for polyline
if pl and rs.IsPolyline(pl):
#get vertices
pts=rs.PolylineVertices(pl)
#create new list, add first point from orig polyline
new_pts=[pts]
#get startying value for Y
curr_y=pts.Y
#loop through the polyline points starting at second point
for i in range(1,len(pts)):
#if Y value is less than or equal to previous, add point to new list
if pts[i].Y<=curr_y:
new_pts.append(pts[i])
#update current Y value
curr_y=pts[i].Y
#check if there are at least two points in new list, add new PL, delete old
if len(new_pts)>1:
rs.DeleteObject(pl)
``````

Hello Helvetosaur, thank you.

It works great. But I am afraid I had to change one rule: Instead of eliminating the point the best would be to move the peak point down in y, by the difference in height to the previous point + an user set value (the same for all):

Sorry for changing after you answered my initial inquiry. I hope its not much trouble.

.

This is certainly possible - just one thing, what happens if in lowering an intermediate point by your user-specified amount below the preceding one, it becomes lower than the next one? Lower that one as well and so on all the way down the line? That’s the only way I see it working consistently…

Something like this:

``````import rhinoscriptsyntax as rs

def RegularizePolyline():
pl=rs.GetObject("Select a polyline",4,True)
if not pl: return
#check for polyline
if rs.IsPolyline(pl):
#get increment value
inc=rs.GetReal("Lowering increment value?",minimum=0)
if inc is None: return
#get vertices
pts=rs.PolylineVertices(pl)
#get startying value for Y
curr_y=pts.Y
#loop through the polyline points starting at second point
for i in range(1,len(pts)):
if pts[i].Y<curr_y:
#if Y value is less than previous, update Y and continue
curr_y=pts[i].Y
else:
#lower current Y value by increment
curr_y-=inc
#set point's Y value to new current Y value and continue
pts[i].Y=curr_y