Python divide brep surfaces to get points

I am trying to get the grasshopper thing, but then in python.

I cannot find the rhinocommon code to divide a surface and get the points from there.
Do you might know the rhinocommon code for that?

Thank you for your response. :smiley:

problem divide brep surfaces to points 00.gh (12.9 KB)

P and C# are light years apart … but you can the gist of the thing (I hope):

PS: What means Brep Surface? You tell me. Or maybe you mean that you want to respect inner/outer Loops for a given BrepFace ? (if so you should use a PointFaceRelation filtering schema [var pfr = face.IsPointOnFace(pt))

I want to divide the brepfaces like with the components to get points.
So, getting the brepfaces, I think I know, but getting the points, I think I do not know.

Is there a rhinocommon code to divide the surface like with the components and get the points.

What does j++ mean?

The syntax for the BrepFaces (a Surface WITH trim info) has as follows. Sure it’s C# … but the RhinoCommon Methods are the same anyway (i++ means increment by 1).

As far as I know, there isn’t any method with this functionality, but as @PeterFotiadis explaind we could achieve this by nested loops:

import Rhino.Geometry as rg
p=[]
for face in brep.Faces:
    uSize, vSize = face.GetSurfaceSize()[1:]
    uDom = face.Domain(0)
    vDom = face.Domain(1)
    uNumberOfSegments = int(uSize/n)
    vNumberOfSegments = int(vSize/n)
    for i in range(uNumberOfSegments+1):
        for j in range(vNumberOfSegments+1):
            uParam = uDom.ParameterAt(i/uNumberOfSegments)
            vParam = vDom.ParameterAt(j/vNumberOfSegments)
            p.append(face.PointAt(uParam, vParam))

ForestOwl.gh (13.9 KB)

1 Like

thank you :smiley:

You could extend that approach to create panels, and also organize your lists as rows/columns using the tree helper functions. (If you are using Rhino 6). This example uses a dictionary to hold the point location, using row and column(i and j) location. Very similar to how paneling tools indexes point grids.

import Rhino
import ghpythonlib.treehelpers as th

pts = {}
srfs = []
grid = []

nrows = U
ncolumns = V

UDomain = Rhino.Geometry.Interval(0,U)
VDomain = Rhino.Geometry.Interval(0,V)
srf.SetDomain(0, UDomain)
srf.SetDomain(1, VDomain)

for i in range(0,nrows+1):
    gcolumn = []
    for j in range(0,ncolumns+1):
        pts[(i,j)] = Rhino.Geometry.Surface.PointAt(srf,i,j)
        gcolumn.append(Rhino.Geometry.Surface.PointAt(srf,i,j))
    grid.append(gcolumn)
  
for i in range(0, nrows):
    pcolumn = []
    for j in range(0, ncolumns):
        panel = Rhino.Geometry.NurbsSurface.CreateFromCorners(pts[i,j],pts[i+1,j],pts[i+1,j+1],pts[i,j+1])
        pcolumn.append(panel)
    srfs.append(pcolumn)

srfs = th.list_to_tree(srfs)
grid = th.list_to_tree(grid)

srf : type hint Surface, Item Acces
U: type hint Integer, Item Access
V: type hint Integer, Item Access

Or, if you were using native components, you could just use the Mesh Surface Component, Explode the mesh, get the vertices of the faces, then make surface panels from the 4 points, (assuming a quad mesh to start with).

4 Likes