Export several bRepBodies into one stl file

Export several bRepBodies into one stl file

NuofanQiu
Enthusiast Enthusiast
510 Views
2 Replies
Message 1 of 3

Export several bRepBodies into one stl file

NuofanQiu
Enthusiast
Enthusiast

In Fusion360 API, it seems that it only support exporting geometry which to be 'an Occurrence, the root Component, or a BRepBody'.

NuofanQiu_0-1706089044465.png

However, I want export a BRepBodies into a stl file.

Is there any method to do that?

Because I want to use different mesh files for visualization and collision in robotics.

Also, is there any API to access the group object?

NuofanQiu_1-1706089316489.png

Like these two group 'visual' and 'collision' in bodies group?

0 Likes
Accepted solutions (1)
511 Views
2 Replies
Replies (2)
Message 2 of 3

BrianEkins
Mentor
Mentor
Accepted solution

Fusion doesn't support that in the UI, but here's a script that will write all selected bodies into a single STL file. It maintains their current position. The bodies need to be selected before running the script.

 

Fusion does support exporting a component, which can have any number of bodies. This takes advantage of that by creating a new design, copying the selected bodies into the root component of the new design, and then exporting the root component. It then closes the new design without saving.

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface

        # Get the currently selected bodies.
        bodies = []
        tempBRep = adsk.fusion.TemporaryBRepManager.get()
        for selection in ui.activeSelections:
            if isinstance(selection.entity, adsk.fusion.BRepBody):
                # Create a temporary B-Rep copy of the body and add it to the list.
                # Creating a copy maintains the current position of the body.
                bodies.append(tempBRep.copy(selection.entity))

        # Create a new design.
        newDoc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        des: adsk.fusion.Design = newDoc.products.itemByProductType('DesignProductType')

        # Make it a direct modeling design. No parametrics are needed so this is faster.
        des.designType = adsk.fusion.DesignTypes.DirectDesignType

        # Add the bodies to the root component of the new design.
        root = des.rootComponent
        for body in bodies:
            root.bRepBodies.add(body)

        # Export the root component as STL.
        exportMgr = des.exportManager
        stlOptions = exportMgr.createSTLExportOptions(root, 'C:/Temp/MultiBody.stl')
        stlOptions.sendToPrintUtility = False
        exportMgr.execute(stlOptions)

        # Close the document, without saving.
        newDoc.close(False)

        ui.messageBox('Finished.')       
    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

NuofanQiu
Enthusiast
Enthusiast

Well, thank you for your reply.
But I do hope that Fusion API can support exporting bRepBodies.

0 Likes