Fusion360で翼型の連番CSVをインポートしてスプラインでつなぐPythonスクリプトを作成した
公式のドキュメントやサンプルコードはこちら
≫Fusion 360 Help _ Fusion 360 API Reference Manual
≫Fusion 360 Help _ API Samples
スクリプトの作り方
↓そもそもの翼型の読み込み方はこちら
スクリプトの追加の仕方は以下のサイトを参考にした
↓各種インストールについてはこちら
ソースコード
もともとFusion360に組み込まれているImportSplineCSV
というスクリプトを参考に,連番CSVをインポートできるようにプログラムを改良した
CSVファイル名は「(ファイル名)_0000.csv」といった形を想定しており,(x, y, z)の値がcm単位で入力されているものとする
#Author-Autodesk Inc.
#Description-Import spline from serialized csv file
import adsk.core, adsk.fusion, traceback
import io
def run(context):
ui = None
try:
# Black magic for Fusion360 launching
app = adsk.core.Application.get()
ui = app.userInterface
# Get all components in the active design.
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
# Launch a browser for csv file selection
# Choose the largest number in the serialized csv files
title = 'Import Serialized csv'
if not design:
ui.messageBox('No active Fusion design', title)
return
dlg = ui.createFileDialog()
dlg.title = 'Open CSV File'
dlg.filter = 'Comma Separated Values (*.csv);;All Files (*.*)'
if dlg.showOpen() != adsk.core.DialogResults.DialogOK :
return
filename = dlg.filename
# Create the list of serialized csv files
basename=filename[:-8]
index_max=filename[-8:-4]
filetype=filename[-4:]
filenames=[basename+'{:0=4}'.format(index)+filetype for index in range(0,int(index_max)+1,1)]
# Get the root component of the active design
rootComp = design.rootComponent
# Create sketch
sketches = rootComp.sketches
sketch = sketches.add(rootComp.xYConstructionPlane)
for filename in filenames:
with io.open(filename, 'r', encoding='utf-8-sig') as f:
points = adsk.core.ObjectCollection.create()
line = f.readline()
data = []
TE=True
# Read airfoil points data from csv file
while line:
pntStrArr = line.split(',')
data=[]
for pntStr in pntStrArr:
try:
data.append(float(pntStr))
except:
break
if len(data) >= 3 :
if TE:
point_TE = adsk.core.Point3D.create(data[0], data[1], data[2])
points.add(point_TE)
TE=False
else:
point = adsk.core.Point3D.create(data[0], data[1], data[2])
points.add(point)
line = f.readline()
# Add the trailing edge point into "points"
points.add(point_TE)
if points.count:
# Add spline of airfoil
sketch.sketchCurves.sketchFittedSplines.add(points)
else:
ui.messageBox('No valid points', title)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
17∼28行で開かれるブラウザで,連番CSVファイルの一番数字が大きいファイルを選択する
30~34行で,0000~(一番大きい数字)
までのファイル名のリストを作成している.インポートするファイルの開始番号や間隔を変更したければ,range(0,int(index_max)+1,1)
の部分を変更すればいい
66∼67行目で,points
の最後に後縁の点を加えることで,翼型のスプラインが閉曲線になるようにしている.
コードの詳細は公式のドキュメントを参考にしてほしい
≫Fusion 360 Help _ Fusion 360 API Reference Manual
スクリプトの実行
実際にスクリプトを実行してみる
TOOLS→ADD-INS→Scripts→MyScripts→ImportSerializedCSVを選択してRunをクリック

連番CSVの一番大きな番号のファイルを選択して開く

安心と信頼の「応答なし」を経て,スプラインがインポートされる

PCのスペックにもよるが,インポートする翼型の座標点数は少なめにしたほうが良い
今回の座標点数は60点としてある
SplineからBodyの作成
インポートしたSplineからBodyを作成する
SURFACE→CREATE→Loftをクリック

Bodyを構成するスプラインを選択→OKをクリック

SURFACE→CREATE→Patchをクリック

両端のSplineを選択→OKをクリック

SURFACE→MODIFY→Stitchをクリック

すべての面を選択→OKをクリック

Bodyが作成される

まとめ
連番CSVをFusion360にインポートしてスプラインでつなぐPythonスクリプトを作成した
これがあれば機体のモデリングがかなり楽になる

↓ロフトまでやってしまうPythonスクリプトはこちら
↓関連記事


コメント