Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to export Step file of each part in assembly?

1 REPLY 1
Reply
Message 1 of 2
ruban2
120 Views, 1 Reply

How to export Step file of each part in assembly?

Hello

I know method to export step file of assembly. https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-B801DDA8-9A0C-42AD-AC06-F8244CA08D65 

 

But my assembly include many parts.
so I'd like to export step file of each part.

But I don't know method.

 

1 REPLY 1
Message 2 of 2
kandennti
in reply to: ruban2

@ruban2 .

 

We don't have enough information to know exactly what you want.
(e.g. depth of the component, you want the output in the position it is positioned at the joint, etc.)

 

We have created these scripts in anticipation.

# Fusion360API Python script

import traceback
import adsk.core as core
import adsk.fusion as fusion
import pathlib
import re

EXPORT_FOLDER = pathlib.Path(r'C:\temp')

def run(context):
    ui = core.UserInterface.cast(None)
    try:
        app: core.Application = core.Application.get()
        ui = app.userInterface
        des: fusion.Design = app.activeProduct
        root: fusion.Component = des.rootComponent

        exportMgr: fusion.ExportManager = des.exportManager

        app.executeTextCommand(u'Transaction.Start export_step')
        set_all_lightbulb(False)

        # export root component
        root.isBodiesFolderLightBulbOn = True
        path = str(EXPORT_FOLDER / get_export_file_name(f'{root.name}') )
        stpOptions: fusion.STEPExportOptions = exportMgr.createSTEPExportOptions(
            path,
            root
        )
        exportMgr.execute(stpOptions)
        root.isBodiesFolderLightBulbOn = False

        # export occurrence
        for occ in root.occurrences:
            occ.isLightBulbOn = True

            path = str(EXPORT_FOLDER / get_export_file_name(f'{occ.name}') )
            stpOptions = exportMgr.createSTEPExportOptions(path, root)
            exportMgr.execute(stpOptions)

            occ.isLightBulbOn = False

        app.executeTextCommand(u'Transaction.Abort')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


def get_export_file_name(fileName: str) -> str:
    return re.sub(r'[\\|/|:|?|.|"|<|>|\|]', '_', fileName)


def set_all_lightbulb(isLight: bool) -> None:
    app: core.Application = core.Application.get()
    des: fusion.Design = app.activeProduct
    root: fusion.Component = des.rootComponent

    root.isBodiesFolderLightBulbOn = isLight

    occ: fusion.Occurrence = None
    for occ in root.allOccurrences:
        occ.isLightBulbOn = isLight

 

If it is different from what you want, please attach as simple and specific f3d/f3z files as possible.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report