Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Author-
- #Description-
- # To install/use:
- # 1. Open Fusion 360.
- # 2. Hit Shift-S to bring up the "Scrips and Add-Ins" window.
- # 3. Click "Create".
- # 4. Select Python.
- # 5. Name the script "Save Visible as STP-STL-3MF" and click "Create".
- # 6. Click "Edit". Your PY IDE / text editor should appear.
- # 7. Paste this script in and save.
- # 1. Hit Shift-S to bring up the "Scrips and Add-Ins" window.
- # 2. Select "Save Visible as STP-STL-3MF".
- # 3. Click "Run".
- # 4. Look for your output in this folder: "%appdata%\Autodesk\Autodesk Fusion 360\API\Scripts\Save Visible as STP-STL-3MF\out"
- import adsk.core, adsk.fusion, traceback
- import os.path, sys
- def run(context):
- ui = None
- try:
- app = adsk.core.Application.get()
- ui = app.userInterface
- # get active design
- product = app.activeProduct
- design = adsk.fusion.Design.cast(product)
- # get root component in this design
- rootComp = design.rootComponent
- # create a single exportManager instance
- exportMgr = design.exportManager
- # get the script location
- scriptDir = os.path.dirname(os.path.realpath(__file__))
- # Create out dir if it does not exist
- outDir = scriptDir + '/' + 'out'
- if not os.path.exists(outDir):
- os.mkdir(outDir)
- # Create design dir if it does not exist
- designDir = outDir + '/' + rootComp.name
- if not os.path.exists(designDir):
- os.mkdir(designDir)
- # export the root component in 3MF format
- fileName = designDir + '/' + rootComp.name
- stpOptions = exportMgr.createC3MFExportOptions(rootComp, fileName)
- exportMgr.execute(stpOptions)
- # export the occurrence one by one in the root component to a specified file
- allOcc = rootComp.allOccurrences
- for occ in allOcc:
- if occ.isLightBulbOn:
- fileName = designDir + '/' + occ.component.name
- # export the occurrence in STL format
- stlExportOptions = exportMgr.createSTLExportOptions(occ, fileName)
- stlExportOptions.sendToPrintUtility = False
- exportMgr.execute(stlExportOptions)
- # export the occurrence in STP format
- stpOptions = exportMgr.createSTEPExportOptions(fileName, occ.component)
- exportMgr.execute(stpOptions)
- except:
- if ui:
- ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement