Grasshopper

algorithmic modeling for Rhino

Hello,

As shown in the picture, I have a surface (red) with a certain number of surface points and some boxes (green) that are intersecting this surface.

I'd like to evaluate which points are inside the breps and discard them, but I can't find a Python command to do this.

Does a simple method/command even exist or can someone suggest a workaround for this?


Thank you.

Views: 4390

Attachments:

Replies to This Discussion

You could use the Brep.IsPointInside method. See attached definition.

Attachments:

hi Anders,

just a quick question .. how did you reach the function without importing Rhino.Geometry?!

If you set the input parameter type hint to brep the GHPython component will pass the input as an instance of the brep class. Meaning that you can call methods and properties directly on x using the dot notation syntax.

i used to import Rhino.Geometry then convert the Guid using (coerce3dpoint) or (coercebrep) .. but that's much easier !!

thank you

Hi, is it possible to reverse this so that only the points inside the Brep are output?

Cheers.

Thanks for the command. I'd never have found it without your help, because the Rhinoscript Syntax help seems to be rather restricted with the number of commands that are searchable.  

Maybe you could still help me with a loop problem that I encounter now?

import rhinoscriptsyntax as rs

evalPtLt = []

for i in range(len(points)):
for j in range(len(context)):
if context[j].IsPointInside(points[i],0.01,True):
pass
else:
evalPtLt.append(points[i])

a = evalPtLt

I feed the Python container 4 breps and 612 points to evaluate. The command works like a charm and eliminates 5 points, however the loop saves 2443 points to the new list evalPtLt, because it loops 4 times for each brep and 612 times for each point within each brep.
The result should be 607 points (612 initial points - 5 conflicting pts), but I can't figure it out. I'm still a programing noob sort of.

Thanks again!! :)

i think it's because the nested loop checks for each point; If it is not inside the first brep then it will be added to the list, then it will check again... if it is not inside the next brep it will duplicate the point again inside the list .. so we have to eliminate any point that had been inside any brep.

i think this could be one of the answers .. 

evalPtLt = []
for i in range(len(points)):
    for j in range(len(context)):
        if context[j].IsPointInside(points[i],0.01,True): break
    else: evalPtLt.append(points[i])
a = evalPtLt

Unfortunately, the break doesn't bring the desired effect.
It reduces the number of points to 2437, but there should only be 612-5=607 remaining points in the list.

Any ideas?

i am not sure why i it didn't work .. i tried myself and there were no duplicates .. but can you make sure that you called (else) for the loop not for (if) ?? 

like this:

anyhow you can check the attached file ..

Attachments:

Oh, thank you so such. As suspected, the else statement was indented to far.
I didn't know that you could use it that way.

Do you know any good books or resources to get more proficient in Python and Rhinoscripting?

glad it worked !

i found the (else) trick here .. 

"... and a loop’s [else] clause runs when no [break] occurs ..."

for the books, i think (RhinoPythonPrimer) is very helpful, plus python tutorial here. whenever you find other helpful resources, share it please :)

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