Hi,

I am trying to define a new Brep object in RhinoCommon, following this Dale’s C++ sample

https://github.com/mcneel/Rhino5Samples_CPP/blob/master/SampleBrepCommands/cmdSampleTrimmedPlane.cpp

… but it looks like I’m missing something.

This is the code that gives me an invalid brep:

It should trim a PlaneSurface by an ArcCurve (a circle)

import Rhino

import math

def main():

## define surface

surf = Rhino.Geometry.PlaneSurface(

Rhino.Geometry.Plane.WorldXY,

Rhino.Geometry.Interval( -100, 100 ),

Rhino.Geometry.Interval( -100, 100 ) )

## draw surface

Rhino.RhinoDoc.ActiveDoc.Objects.AddSurface( surf )

## define outer curve

circ = Rhino.Geometry.Circle( 75 )

curve3d = Rhino.Geometry.ArcCurve( circ )

## draw outer curve

Rhino.RhinoDoc.ActiveDoc.Objects.AddCurve( curve3d )

Rhino.RhinoDoc.ActiveDoc.Views.Redraw()

## get curve 2D

tolr = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance

curve2d = surf.Pullback( curve3d, tolr )

vertexpnt = curve3d.PointAtStart

## surface orientation

backsurf = False

## curve orientation

backedge = False

## build brep:

rep = Rhino.Geometry.Brep()

## add vertex

vertex = rep.Vertices.Add(

vertexpnt, Rhino.RhinoMath.UnsetValue )

vertexindex = vertex.VertexIndex## add curve 3D

cur3dindex = rep.AddEdgeCurve( curve3d )

## add edge

edge = rep.Edges.Add(

vertexindex, vertexindex, cur3dindex, Rhino.RhinoMath.UnsetValue )## add surface

surfindex = rep.AddSurface( surf )

## add face

face = rep.Faces.Add( surfindex )

## add loop

loop = rep.Loops.Add( Rhino.Geometry.BrepLoopType.Outer, face )

## add curve 2D

cur2dindex = rep.AddTrimCurve( curve2d )

## add trim

trim = loop.Trims.Add( edge, backedge, loop, cur2dindex )

trim.IsoStatus = Rhino.Geometry.IsoStatus.None

trim.TrimType = Rhino.Geometry.BrepTrimType.Boundary

trim.SetTolerances( Rhino.RhinoMath.UnsetValue, Rhino.RhinoMath.UnsetValue )## set surface orientation

face.OrientationIsReversed = backsurf

print ‘Brep is valid: %s’ % str( rep.IsValid )

main()

Any advise to help me find the error(s) ?

Thanks