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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Script/API to change parameter and then export as STL

Message 1 of 4
3414 Views, 3 Replies

Script/API to change parameter and then export as STL

I'm looking to create a script to export a design to STL. I could do manually but I would like to create a range of sizes of an object as STL's. So lets say I want to change a parameter from 10x10mm to 10x20mm, then 10x30mm and so one doing an export each time. So if I do that all the way up to 100x100mm then I should have 100 files! I'm not doing that manually so any advice would be appreciated on how to achieve this. Thanks!!!

Message 2 of 4

Someone must have done this before? 🙂 

Message 3 of 4
in reply to: martin.rourke

The guts of how to do this is fairly simple and can be pieced together from existing samples.  By "guts" I mean the basic operations that will be happening; edit one or more parameters, export the model to stl.  Where it gets more difficult, mainly because there are so many options and it's easy to get carried away with options, is defining the user interface.  You could have a fairly complex dialog that lets the user specify which parameters will be changing and the range of values over the changes, the number of steps, the naming scheme for the output files, and the output folder.  You could spend a few minutes on the basic functionality and a few days on the UI.  Another option would be for the program to consume an Excel file (easiest would be CSV) where each row would have the values and output filename to use.  That would be easier and provide more flexibility because each iteration could be completely different but it would require more work to set up the CSV file.


Below is a simple program with the "guts".  It's hard-coded to do what you described originally. 


def run(context):
    ui = None
        app = adsk.core.Application.get()
        ui = app.userInterface
        design = adsk.fusion.Design.cast(app.activeProduct)
        # Get the root component of the active design
        rootComp = design.rootComponent

        # Specify the folder to write out the results.
        folder = 'C:/Temp/STLExport/'

        # Get the parameters named "Length" and "Width" to change.
        lengthParam = design.allParameters.itemByName('Length')
        widthParam = design.allParameters.itemByName('Width')

        for i in range(1,11):
            for j in range(1,11):
                length = i * 10
                width = j * 10
                lengthParam.expression = str(length)
                widthParam.expression = str(width)
                # Let the view have a chance to paint just so you can watch the progress.
                # Construct the output filename.
                filename = folder + str(length) + 'x' + str(width) + '.stl'
                # Save the file as STL.
                exportMgr = adsk.fusion.ExportManager.cast(design.exportManager)
                stlOptions = exportMgr.createSTLExportOptions(rootComp)
                stlOptions.meshRefinement = adsk.fusion.MeshRefinementSettings.MeshRefinementMedium
                stlOptions.filename = filename
        if ui:

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 4 of 4
in reply to: ekinsb

This is brilliant! Thanks for the help!!!!!! Life saver as it has saved me manually exporting 100 files 🙂

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

Post to forums  

Autodesk Design & Make Report