Adding trim curve to brep



I want to add a trim curve to a brep.

I have a brep and a projected curve in a brep’s face. When I try to add the trim curve, brep becomes invalid. I’ll appreciate so much if someone could show me the basic steps to create a trim curve in a brep’s face. The curve is not an edge from the brep, is a closed curve that has been projected or created on a brep’s face.

Thanks in advance.

(Menno Deij - van Rijswijk) #2

There are some examples here:

Check the “Face with hole” and “Trimmed plane” for info on adding trims.


Thanks for the answer, yes, I checked this example and I’m trying to add a closed trim curve to a sphere brep, but brep is not valid. Basically, I do this:

//Add vertex
OnBrepVertex v = brep.NewVertex(curve.PointAtStart( ) );
v.m_tolerance = 0.0;

//Add 3D curve
brep.m_C3.Append( curve );

//Create edge with closed curve
OnBrepEdge edge = brep.NewEdge( ref v, ref v );
edge.m_tolerance = 0.0;  // this simple example is exact - for models with
edge.ChangeEdgeCurve( brep.m_C3.m_count - 1 ); //assign curve to edge

//Create Loop
OnBrepFace face = brep.m_F[ 0 ];
OnBrepLoop loop = brep.NewLoop( IOnBrepLoop.TYPE.inner, ref face );
OnSurface srf = brep.m_S[ face.m_si ];

//Create 2D curve on surface
curveParam = CreateCurve2D( curve, srf )

//Add new Trim
int c2i = brep.m_C2.Count( );
brep.m_C2.Append( curveParam );            
OnBrepTrim trim = brep.NewTrim( ref edge, false, ref loop, c2i );

trim.m_iso = IOnSurface.ISO.not_iso;;
trim.m_type = IOnBrepTrim.TYPE.boundary; 
trim.set_m_tolerance( 0, 0 );
trim.set_m_tolerance( 1, 0 ); 

Edge, loop and trim are valid, but Brep is not valid when I add new loop, and never becomes valid.

(Menno Deij - van Rijswijk) #4

It is possible, maybe, that your curve has the wrong direction. You may want to try to flip it to see what happens.

For invalid BREPs (in fact for any geometry) you can use IsValidWithLog (or similarly called method) to get a string with analysis of what is wrong. This helped me to figure out why the BREPs I created with a trim were invalid.


I also need this function,but I find your codes can’t compile,can you give the vhole codes.