Grasshopper

algorithmic modeling for Rhino

Hello,

I have a python script that will output a list of points (x-, y- and z-coordinates) (see image). Now I want to delete the points that lie between certain x- and y-values. For instance if a point lies between a x-value of 2750-3000 AND a y-value 1500-1750 the point has to be deleted, in this example point nr. 13 has to be removed from the list.

Thanks in advance 

Views: 1219

Attachments:

Replies to This Discussion

Have a look at this.

class MyPoint:

     X = 0
     Y = 0

   def __init__(self, x , y):
      self.X = x
      self.Y = y

   def __repr__(self):
      return "({0}, {1})".format(self.X, self.Y)


Points= [MyPoint(0,1),MyPoint(2751,1600),MyPoint(3001,1600), MyPoint(3000,1500), MyPoint(2999,1749)]

XRange = (2750,3000)
YRange = (1500,1750)

filtered = [p for p in Points if XRange[0] < p.X < XRange[1] and YRange[0] < p.Y < YRange[1]]

print(filtered)

I managed to solved it by meself via another method. However this is an even more efficient method, thanks.

Just to show up a python-syntax which is great ;)

Unless I'm misunderstanding the problem, this is pretty straightforward using a conditional statements within a loop:




Attachments:

No you didn't misunderstood the problem, this was exactly what I was looking for. Short and effective piece of script, thank you.

Awesome Anders. How can we select the selective points what we want. may be by index numbers or any other method. Would appreciate if you could help on this. 

Thanks in advance

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