Skip to content

Instantly share code, notes, and snippets.

@tonosaman
Last active March 2, 2017 07:35
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 tonosaman/a983e7b061c49a467ea1039f52ad718f to your computer and use it in GitHub Desktop.
Save tonosaman/a983e7b061c49a467ea1039f52ad718f to your computer and use it in GitHub Desktop.
Femap BASIC Script: exports all AnalysisSet as .nas file

カスタムツールへ登録して使用する方法

C:\FEMAPv1031J\api\にディレクトリを作成し、マクロファイルexport-Nastran-AnalysisSet.basを配置する。

(「カスタムツール>追加」で.basファイルを指定すると、Femapにより上記ディレクトリ配下にコピーされる。)

APIプログラムの編集方法

  1. Femapメニューより「ツール>プログラミング>APIプログラミング」を選択
  2. APIプログラミングウィンドウの上部の「開く」アイコンをクリック
  3. マクロファイルexport-Nastran-AnalysisSet.basを読込
  4. APIプログラミングウィンドウ上部の「実行」アイコンをクリック

参考資料

FEMAP BASIC Scripting Language Reference - Extras Springer

' アクティブのモデルファイル(.modfem)の拡張子を除いたファイル名に、「_<解析セット名>.nas」を付けたファイルを一括エクスポートします。
' 注意: 解析セット名にはファイル名として指定できない文字を含めないようにしてください。
'
' [FEMAP BASIC Scripting Language Reference - Extras Springer](http://extras.springer.com/2002/978-3-540-41483-4/wtp2000/femap/docs/basic.pdf)
Sub Main
Dim model As Object
Set model = GetObject(, "femap.model")
Dim ans As AnalysisMgr
Set ans = model.feAnalysisSet
While ans.Next()
ans.Active = ans.ID
Dim mdlId As Huge_
model.feAppGetModel(mdlId)
Dim mdlName As String
model.feAppGetModelName(mdlId, mdlName)
Dim outfile As String
outfile = Left(mdlName, Len(mdlName) - Len(".modfem")) + "_" + ans.title + ".nas"
ls = Dir(outfile)
If ls = "" Then
' ans.Solver -> 4=MSC/NASTRAN, 31=NE/Nastran, 36=NX Nastran
' Nastran brand -> 0=MSC、1=NE、2=UAI、3=CSA、4=SSS、 5=Cosmic、6=ME、7=VR、8=NX
Select Case ans.Solver
Case 4
model.feFileWriteNastran(0, outfile)
Case 31
model.feFileWriteNastran(1, outfile)
Case 36
model.feFileWriteNastran(8, outfile)
Case Else
MsgBox("エラー: 解析セット「" + Str(ans.ID) + ".." + ans.title + "」のソルバーがNASTRANではありません。この解析セットはスキップされました。")
End Select
Else
MsgBox "エラー: 解析セット「" + Str(ans.ID) + ".." + ans.title + "」の出力先ファイル(" + outfile + ")が既に存在しています。この解析セットはスキップされました。"
End If
Wend
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment