I’m trying to use “Brep.CreateOffsetBrep” in order to emulate “OffsetSrf” command but when I use the surface attached I end up with an odd polisurface.
I’m using the following code:
Dim outBlends As Brep() = {}
Dim outWalls As Brep() = {}
Dim offsetBrep As Brep() = Brep.CreateOffsetBrep(targetSurface.ToBrep(), 2, True, False, doc.ModelAbsoluteTolerance, outBlends, outWalls)
import Rhino
import scriptcontext as sc
def test_offset_brep():
filter = Rhino.DocObjects.ObjectType.Brep
rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select Brep to offset", False, filter)
if not objref or rc != Rhino.Commands.Result.Success:
return
brep = objref.Brep()
if not brep:
return
tol = sc.doc.ModelAbsoluteTolerance
offsets, blends, walls = Rhino.Geometry.Brep.CreateOffsetBrep(brep, 2.0, True, False, tol)
if offsets:
for b in offsets:
sc.doc.Objects.AddBrep(b)
sc.doc.Views.Redraw()
if __name__ == "__main__":
test_offset_brep()
I’m able to create a perfect offset brep following your example so it’s something I’m doing wrong inside the tool I’m developing.
Sorry for posted you about I problem that I have in my own code and thank you for pointing me in the right direction
It seems that the problem is related with DuplicateFace() that creates a polysurface.
I’m using this code to explode the brep and just use the surfaces I need:
Dim myNewBrep As Brep() = {}
Dim outBlends As Brep() = {}
Dim outWalls As Brep() = {}
Dim offsetBrep As Brep() = Brep.CreateOffsetBrep(targetSurface.ToBrep(), 2, True, False, doc.ModelAbsoluteTolerance, outBlends, outWalls)
For Each face As BrepFace In offsetBrep(0).Faces
Dim brep As Brep = face.DuplicateFace(True)
If Not targetSurface.ToBrep.IsDuplicate(brep, doc.ModelAbsoluteTolerance) Then
myNewBrep.Add(brep)
End If
Next
If I use face.DuplicateSurface() I get a geometry that looks like ok.
I’m trying to create a brep that does not have the faces that are part of the targetSurface because later I would like to join with other brep.
I changed my strategy and instead of “create a new brep with some brepFaces missing” I tried to remove brepFaces directly in the brep created by CreateOffsetBrep and it seems to work. But I have to tune the code that is able to detect that a BrepFace is part of the targetSurface.