I am trying to write a Python script that iterates over all the faces of a mesh, checks various conditions, and selects only a few faces. I was successful in determining the orientation of the surface, which excluded most of the surfaces. Now, I would like to further narrow down my selection of faces, but I’m stuck. Most rhinoscriptsyntax functions require a GUID, which I apparently lose once I coerce the geometry. As far as I know, I can’t access the GUID with a function like face.guid() or similar. Is there a better way of doing this? Could I take note of the GUID at the start?
(It seems, that the guid from the start is not iterable.)
Thanks in advance for any assistance!
import Rhino.Geometry as rg
import rhinoscriptsyntax as rs
import math
import Rhino
angle_threshold_degrees = 40
mesh = rs.coercemesh(mesh)
#mesh = rs.ExplodeMeshes(mesh)
faces = rs.MeshFaces(mesh)
normals = rs.MeshFaceNormals(mesh)
filtered_faces = []
for i in range(0, len(normals)):
normal = normals [i]
angle = rg.Vector3d.VectorAngle(-normal, rg.Vector3d.ZAxis)
angle_degrees = math.degrees(angle)
if -angle_threshold_degrees < angle_degrees < angle_threshold_degrees:
face = faces[i]
filtered_faces.append(face)
else:
continue
direction = -rg.Vector3d.ZAxis
area = rs.MeshArea(face)
#detect if a vector starting at the face center (to direction -z) would collide with the mesh
#I would use the face centre as available above. However, how do I figure out the intersection with the mesh & in code?
#calculate the area of the face, exclude if smaller than treshold
#I was thinking of using the vertices and calculating it myself
#check if the remaining faces are neighbours
#could omit this if to difficult
#if close enough merge them
#I was thinking of using cull duplicates here