How to create a revolved solid using Rhino Common

I’m trying to convert a RevSurface in to a solid Brep. In this instance the revolve happens to be 180 degrees. I’ve tried several combinations of CapPlanarHoles (also tried CreatePlanarBreps from the revolve’s loops), MergeCoplanarFaces, flipping solid orientation, flipping orientation-inverted faces, etc. But the result is always either open, invalid, sometimes totally garbled, or sometimes it is is closed and appears perfect (as in the example I’ll post here) but for some reason can’t be used for boolean operations.

Interestingly even though there are several coplanar faces, MergeCoplanarFaces seems to always fail dramatically.

I’ll attach a C# script component in case any one cares to take a look. Hopefully there is some common knowledge that I’m just missing here. Thanks!

revolve problem.txt (2.3 KB)

You can copy paste code into a post…

code

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];
  }

}

Ok the solution seems painfully obvious now… I included my revolve line as part of my profile, as you would in Solidworks etc. But of course this is not a “solid” revolve and that single line in the middle really messes up the resulting surface