Brep.CreateOffsetBrep does not generate the same as the OffsetSrf command

Hi,

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)

This is the original surface:

This is what I get using “CreateOffsetBrep”:

This is what I get the “OffsetSrf” command:

What am I doing wrong?

surface.3dm (58.4 KB)

Thanks for your help,
Jordi

Hi @Jordi_Llonch,

This seems to work correctly in Rhino 7:

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()

test_offset_brep.3dm (93.7 KB)

test_offset_brep.py (665 Bytes)

What am I missing?

Thanks,

– Dale

Hi Dale,

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 :slight_smile:

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.

Hi @Jordi_Llonch,

Sorry, I don’t understand what your code is doing. Why are you creating a Brep from another Bree’s components? What problem are you trying to solve?

— Dale

Hi @dale,

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.