I’d like some pointers on how to convert large numbers of planar surfaces into hatches, while retaining the surfaces properties such as display colour etc of each surface/hatch.
I need to do this so I can export the file into illustrator with the shape fills intact.
I have not tested this a whole lot. But this is the general idea:
import Rhino
import scriptcontext as sc
def test_surface_to_hatch():
filter = Rhino.DocObjects.ObjectType.Surface
rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select planar surface", False, filter)
if not objref or rc != Rhino.Commands.Result.Success:
return
brep = objref.Brep()
if not brep or not brep.Faces.Count == 1:
return
face = brep.Faces[0]
tol = sc.doc.ModelAbsoluteTolerance
if not face or not face.IsPlanar(tol):
print("Not a planar surface.")
return
curves = []
for loop in face.Loops:
for trim in loop.Trims:
if trim.TrimType == Rhino.Geometry.BrepTrimType.Seam:
continue
edge = trim.Edge
if edge is None:
continue
curves.append(edge.EdgeCurve)
borders = Rhino.Geometry.Curve.JoinCurves(curves, 2.1 * tol, False)
if borders:
hatches = Rhino.Geometry.Hatch.Create(borders, 0, 0.0, 1.0, tol);
if hatches:
for hatch in hatches:
sc.doc.Objects.AddHatch(hatch, objref.Object().Attributes)
sc.doc.Views.Redraw()
if __name__ == "__main__":
test_surface_to_hatch()