Skip to content

Instantly share code, notes, and snippets.

@dmgerman
Last active February 1, 2025 17:59
Show Gist options
  • Save dmgerman/785ed6250c66dd596894650803233294 to your computer and use it in GitHub Desktop.
Save dmgerman/785ed6250c66dd596894650803233294 to your computer and use it in GitHub Desktop.
sets len to a list of values, then exports a stl for each
"""This file acts as the main module for this script."""
import traceback
import adsk.core
import adsk.fusion
import os
# import adsk.cam
# Initialize the global variables for the Application and UserInterface objects.
app = adsk.core.Application.get()
ui = app.userInterface
def run(_context: str):
"""This function is called by Fusion when the script is run."""
def export_stl(len):
lenParam.expression = str(len)
adsk.doEvents()
filename = os.path.join(folder, f"{modelName}_{len}mm.stl")
exportMgr = adsk.fusion.ExportManager.cast(design.exportManager)
stlOptions = exportMgr.createSTLExportOptions(rootComp)
stlOptions.meshRefinement = adsk.fusion.MeshRefinementSettings.MeshRefinementHigh
stlOptions.filename = filename
exportMgr.execute(stlOptions)
return 1
try:
design = adsk.fusion.Design.cast(app.activeProduct)
rootComp = design.rootComponent
modelName = design.rootComponent.name.split(' v')[0]
folder = '/tmp/'
lenParam = design.allParameters.itemByName('len')
assert(lenParam)
(sizesSt, cancelled) = ui.inputBox("Enter the sizes to export for parm len:")
sizes = list(map(int, sizesSt.split()))
count = sum(map(export_stl, sizes))
ui.messageBox(f"Finished exporting {count} stl files with sizes {sizes}")
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
app.log(f'Failed:\n{traceback.format_exc()}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment