Ok thanks Martin, here is the code of a C# script component that shows what I’m trying to do. Everything seems to work fine up until the creation of the RevSurface, conversion to Brep, and converting to a solid.
edit: just to be clear this will output a seemingly valid Brep with IsValid set to True, but I get errors when trying to subtract this geometry in Grasshopper, in Rhino, and in C#
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using Rhino;
using Rhino.Geometry;
using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;
public class Script_Instance : GH_ScriptInstance
{
private void RunScript(ref object brep)
{
Double radius = 4;
Plane p = Plane.WorldZX;
Line revLine;
Curve shape = CreateShape(p,radius, out revLine);
RevSurface rev = RevSurface.Create(shape, revLine, Math.PI, 2*Math.PI);
Brep output = rev.ToBrep();
output = Solidify(output);
brep = output;
}
public static Brep Solidify(Brep b)
{
//b.Faces.SplitKinkyFaces();
b = b.CapPlanarHoles(RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);
if (b.SolidOrientation != BrepSolidOrientation.Outward) b.Flip();
b.Faces.Flip(true);
//b.Compact();
//b.MergeCoplanarFaces(RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);
return b;
}
public static Curve CreateShape(Plane p, double radius, out Line revolveLine)
{
double extension = .05;
List<Curve> curves = new List<Curve>();
curves.Add(new LineCurve(p.PointAt(-extension,extension), p.PointAt(-extension,-radius)));
revolveLine = new Line(p.PointAt(-extension,extension), p.PointAt(-extension,-radius));
curves.Add(new LineCurve(p.PointAt(-extension,extension), p.PointAt(radius,extension)));
curves.Add(new LineCurve(p.PointAt(radius,0),p.PointAt(radius,extension)));
curves.Add(new LineCurve(p.PointAt(-extension,-radius),p.PointAt(0,-radius)));
Circle c = new Circle(p,p.PointAt(radius,-radius),radius);
curves.Add(new Arc(c,new Interval(Math.PI/2,Math.PI)).ToNurbsCurve());
return Curve.JoinCurves(curves)[0];
}
}