brep to mesh in api

brep to mesh in api

Cotral.RD2
Advocate Advocate
1,198 Views
2 Replies
Message 1 of 3

brep to mesh in api

Cotral.RD2
Advocate
Advocate

Hi

Is there a way to convert a brep object to mesh using API?

 

Pavan HEMMEGE VENKATAPPA
Fusion 360 Ultimate User
0 Likes
Accepted solutions (1)
1,199 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor
Accepted solution

The API help hasn't been updated since last year but there is a newer function available since then that makes this relatively easy.  Below is a sample that creates a mesh body from a selected body.  The MeshCalculator object supports many settings to let you control how the mesh is generated.  The sample uses a property that automatically sets the various settings to get a decent result.

 

def createMeshFromBRep():
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)
        root = des.rootComponent

        brepBodySel = ui.selectEntity('Select the B-Rep body', 'Bodies')
        if not brepBodySel:
            return
        brepBody = adsk.fusion.BRepBody.cast(brepBodySel.entity)

        # Get mesh data from the B-Rep body.
        meshCalc = brepBody.meshManager.createMeshCalculator()
        meshCalc.setQuality(adsk.fusion.TriangleMeshQualityOptions.NormalQualityTriangleMesh)
        triangleMesh = meshCalc.calculate()
        
# Create the mesh body. meshBody = root.meshBodies.addByTriangleMeshData(triangleMesh.nodeCoordinatesAsDouble, triangleMesh.nodeIndices, triangleMesh.normalVectorsAsDouble, triangleMesh.nodeIndices) except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Message 3 of 3

Cotral.RD2
Advocate
Advocate

Exactly what I was looking for ! Thanks

Pavan HEMMEGE VENKATAPPA
Fusion 360 Ultimate User
0 Likes