Grasshopper

algorithmic modeling for Rhino

I want to program using GhPython to get the following information for each of the surfaces within a geometry (brep or polygon or mesh geometry):

- surface centroid coordinate and vector of the surface normal

- coordinators of the corners of a surface

However, it seems I could not get the individual surface objects within a geometry in the first place:

Can anybody advise on a general workflow in this regard?

Thank you!

Views: 1601

Replies to This Discussion

Hi Grasshoppe

surfaces are untrimmed NURBS surfaces. When a surface is trimmed, Rhino regards is as a Brep. One single Brep, though, can contain more than one trimmed parts. Therefore, you will have to explode a brep in order to get to its constituent (brep) parts.

Attached is a script that shows how to do that (using rhinoscriptsyntax).

In the future please post the file you are working on. I hope this helps,

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Attachments:

Thank you, Giulio!

I have two new problems in:

1. adding text besides a point (line 16 of the code) doesn't work

2. find corners of a concave surface (line 27&28) (I'm expecting to get the 6 corners of the last surface in the Brep, however, only the corners of the bounding box of the surface are generated)

It seems the rs.SurfacePoints only returens the control points of a surface rather than the actual corners of the surface. Can you advise if there's a way to do it?

Thank you!

Code:

import rhinoscriptsyntax as rs

all_parts = rs.ExplodePolysurfaces(brep)

centers = []
vectors = []
lines = []
vertices = []

cnt = 0

for part in all_parts:
    center, err = rs.SurfaceAreaCentroid(part)
    centers.append(center)
    
    #rs.AddText(str(cnt), center)
    
    uv = rs.SurfaceClosestPoint(part, center)
    vector = rs.SurfaceNormal(part, uv)
    vectors.append(vector)
    
    N_start = center
    N_end = rs.VectorAdd(center, vector)
    line = rs.AddLine(N_start, N_end)
    lines.append(line)
    
    #vertices = rs.SurfacePoints(part)
    vertices = rs.SurfaceEditPoints(part)
    
    cnt +=1

#C = centers
#N = vectors
#L = lines
V = vertices

#todo:
#explore the surface methods in rhinoscript.surface...
#import rhinoscript.surface.

Attachments:

I mean these are the points I want to get:

Hi Giulio,

May I also ask what does the "err" mean in the following code?

center, err = rs.SurfaceAreaCentroid(part)

Thanks!

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service