Last active
April 30, 2020 17:49
-
-
Save onionmk2/6606b27d2e51733d0c5b0483e0b27df4 to your computer and use it in GitHub Desktop.
stepをfusion360にインポートするスクリプト。13行目を自分の環境に合わせて変える。
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
# FusionAPI_python Import3DCadFiles ver0.0.1 | |
# Author-onionmk2 | |
import adsk.core, adsk.fusion, traceback | |
import os.path | |
def run(context): | |
ui = None | |
try: | |
app = adsk.core.Application.get() | |
ui = app.userInterface | |
path = "#{change C:/Users/xxx/ to your directory}C:/Users/xxx/bridge.step" | |
paths = [path] | |
if paths is None: | |
ui.messageBox('Failed: path is none') | |
return | |
# インポートオプション | |
importManager = app.importManager | |
opts = GetOptions(paths, importManager) | |
if opts is None: | |
ui.messageBox('Failed : opts is none') | |
return | |
#インポート | |
ExecImport(opts, importManager, app) | |
ui.messageBox('Success to import ' + path) | |
except: | |
if ui: | |
ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) | |
# #インポート | |
def ExecImport(opts, iptMng, app): | |
des = adsk.fusion.Design.cast(app.activeProduct) | |
root = des.rootComponent | |
for opt in opts: | |
try: | |
iptMng.importToTarget(opt, root) | |
except: | |
pass | |
# #拡張子別インポートオプション取得 | |
def GetOptions(paths, iptMng): | |
opts = [] | |
for path in paths: | |
if not os.path.exists(path): | |
continue | |
_, ext = os.path.splitext(path) | |
if '.F3D' == ext.upper(): | |
opt = iptMng.createFusionArchiveImportOptions(path) | |
if '.IGES' == ext.upper() or '.IGS' == ext.upper(): | |
opt = iptMng.createIGESImportOptions(path) | |
if '.STEP' == ext.upper() or '.STP' == ext.upper(): | |
opt = iptMng.createSTEPImportOptions(path) | |
if '.SAT' == ext.upper(): | |
opt = iptMng.createSATImportOptions(path) | |
if '.SMT' == ext.upper(): | |
opt = iptMng.createSMTImportOptions(path) | |
if opt is None: | |
continue | |
opt.isViewFit = False | |
opts.append(opt) | |
if len(opts) < 1: | |
return None | |
return opts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment