Created
April 30, 2020 17:52
-
-
Save onionmk2/f7918075a454c9c9ae174d5a82cc17ba to your computer and use it in GitHub Desktop.
stepをfusion360からエクスポートするスクリプト。16行目を自分の環境に合わせて変える。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
# export | |
exportMgr = design.exportManager | |
fileName = "#{change C:/Users/xxx to your directory} C:/Users/xxx/bridge.step" | |
stpOptions = exportMgr.createSTEPExportOptions(fileName) | |
exportMgr.execute(stpOptions) | |
# show progressDialog. this is more useful than ui.messageBox because this does not require click to close. | |
pseudo_auto_close_modal("Exporting...") | |
except: | |
if ui: | |
ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) | |
# substitute progressDialog for auto-closing dialog. | |
# https://forums.autodesk.com/t5/fusion-360-api-and-scripts/ambient-alert-to-users-from-api/td-p/6862812 | |
# Unfortunately we haven't yet exposed access to any of the message mechanisms in Fusion except for the message box and a progress bar dialog. | |
def pseudo_auto_close_modal(message): | |
from time import sleep | |
ui = None | |
try: | |
app = adsk.core.Application.get() | |
ui = app.userInterface | |
# Set styles of progress dialog. | |
progressDialog = ui.createProgressDialog() | |
progressDialog.cancelButtonText = 'Cancel' | |
progressDialog.isBackgroundTranslucent = False | |
progressDialog.isCancelButtonShown = True | |
# Show dialog | |
end_progress = 100 | |
progressDialog.show(message, 'Percentage: %p, Current Value: %v, Total steps: %m', 0, end_progress, | |
1) | |
# stop. i have to do this. Otherwise, progress dialog disappear too fast to see. | |
sleep(0.1) | |
# update status. | |
for i in range(end_progress): | |
# If progress dialog is cancelled, stop. | |
if progressDialog.wasCancelled: | |
break | |
# Update progress value of progress dialog | |
progressDialog.progressValue = i + 1 | |
# Hide the progress dialog at the end. | |
progressDialog.hide() | |
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