Skip to content

Instantly share code, notes, and snippets.

@ebith
Created February 10, 2023 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebith/4f124929b8976c2bd623a9ea38e371dc to your computer and use it in GitHub Desktop.
Save ebith/4f124929b8976c2bd623a9ea38e371dc to your computer and use it in GitHub Desktop.
詳細な名前を付けてSTLを出力するFusion 360スクリプト
#Author-ebith
#Description-Output STL with detailed name.
# 謎:
# - availablePrintUtilitiesが空っぽ
# - sendToPrintUtility = Trueとするとfilenameが無視されてGUID固定になる
# Todo:
# - ボディを選べるように
printUtilityPath = 'C:/Users/ebith/scoop/apps/cura/current/UltiMaker-Cura.exe'
import os.path
import subprocess
import tempfile
import traceback
from datetime import datetime
import adsk.core
import adsk.fusion
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
rootComp = design.rootComponent
exportMgr = design.exportManager
with tempfile.TemporaryDirectory() as tmpdirname:
tmpfilename = os.path.join(tmpdirname, f'{rootComp.name} {datetime.now().strftime("%Y-%m-%d %H%M%S")}.stl')
stlRootOptions = exportMgr.createSTLExportOptions(rootComp, tmpfilename)
stlRootOptions.sendToPrintUtility = False
stlRootOptions.meshRefinement = 0 # High
exportMgr.execute(stlRootOptions)
subprocess.run([printUtilityPath, tmpfilename])
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment