OS. Microsoft Wordマクロの例
カスタムのレポートドキュメントのベースとして使用できる解析結果の部分的なレポートを含むMicrosoft Office Wordドキュメントが含まれています。
このドキュメントファイルには、Proという名前のマクロが含まれています。このマクロでは、サポートノードの数、および荷重ケースと荷重の組み合わせの数をチェックし、それらをドキュメントに出力します。その後、選択したノード番号と荷重ケース番号のサポート反力をドキュメントで出力できます。
- STAAD.Proで入力ファイルを開きます。
-
ファイルC:\Users\Public\Public Documents\STAAD.Pro 2023\SamplesSample Models\OpenSTAAD\STAADandWord.docを開きます。
注記: ファイルにマクロが含まれているため、Wordで警告が表示されます。「セキュリティの警告」メッセージ領域で「オプション」ボタンをクリックすると「Microsoft Officeセキュリティオプション」ダイアログが開くので、「このコンテンツを有効にする」オプションを選択して「OK」をクリックします。
- 「Update Nodes and Load Cases」ボタンをクリックします。 「Node Number」と「Load Case Number」の選択項目が選択したファイルのデータで更新されます。
- 「Node Number」と「Load Case Number」で、結果を取得する対象の番号を選択します。
- 「Get Results」をクリックします。 下のテーブルでサポート反力と単位が更新されます。
Wordマクロコード
OpenSTAADマクロの動作を確認するには、開発者ツールを使用してVisual Basic Editorを開きます。
GetSTAAD_Click
Option Explicit
Public objOpenSTAAD As Object
Public Fraction As Double
Public LC As Integer
Public bBadSTAADFile As Boolean
Private Sub GetSTAAD_Click()
'
' STAAD.Pro Macro
' Import STAAD.Pro Data Dynamically into an MS Word document
' using the OpenSTAAD Application object
Dim stdFile As String
Dim DOF As Integer
Dim acell As Cell
'Launch OpenSTAAD Object
Set objOpenSTAAD = GetObject(, "StaadPro.OpenSTAAD")
'Load your STAAD file - make sure you have successfully run the file
objOpenSTAAD.GetSTAADFile stdFile, "TRUE"
STAADFileName.Text = "(None)"
If stdFile = "" Then
MsgBox "This macro can only be run with a valid STAAD file loaded.", vbOKOnly
Set objOpenSTAAD = Nothing
Exit Sub
End If
STAADFileName.Text = stdFile
FillBoxesWithData stdFile
DOF = 0
For Each acell In ActiveDocument.Tables(2).Columns(2).Cells
If (acell.RowIndex <> 1) Then
acell.Range.Text = "0.0"
DOF = DOF + 1
End If
Next acell
Set objOpenSTAAD = Nothing
End Sub
GetResults1_Click
Private Sub GetResults1_Click() Set objOpenSTAAD = GetObject(, "StaadPro.OpenSTAAD") Dim Reactions(6) As Double ' The Integer has been changed to a Long in 2004 to hold higher node numbers Dim Node As Long Dim LC As Long Dim DOF As Integer Dim acell As Cell If (bBadSTAADFile = True) Then MsgBox "Please provide a valid STAAD file, node number and load case number before clicking this button." Exit Sub End If Node = NodeNumber.Text LC = LCNumber.Text objOpenSTAAD.Output.GetSupportReactions Node, LC, Reactions DOF = 0 For Each acell In ActiveDocument.Tables(2).Columns(2).Cells If (acell.RowIndex <> 1) Then acell.Range.Text = Reactions(DOF) DOF = DOF + 1 End If Next acell End Sub
追加サブルーチン
Private Function FillBoxesWithData(strSTAADFile As String)
Dim varCounter1 As Integer
Dim PrimaryLCs As Integer
Dim LoadCombs As Integer
Dim TotalLoads As Integer
' The Integer has been changed to a Long in 2004 to hold higher node numbers
Dim SupportedNodesCount As Long
' The Integer has been changed to a Long in 2004 to hold higher node numbers
Dim SupportedNodeNos() As Long
On Error GoTo ErrorHandler
'Set objOpenSTAAD = CreateObject("OpenSTAAD.Output.1")
SupportedNodesCount = objOpenSTAAD.Support.GetSupportCount()
ReDim SupportedNodeNos(SupportedNodesCount)
Dim nReturn As Long
nReturn = objOpenSTAAD.Support.GetSupportNodes(SupportedNodeNos)
'Fill nodes list box
NodeNumber.Clear
For varCounter1 = 0 To SupportedNodesCount - 1
NodeNumber.AddItem SupportedNodeNos(varCounter1)
Next varCounter1
NodeNumber.Text = SupportedNodeNos(0)
'Fill load list box
'Find out how many primary load cases and load combinations you have
PrimaryLCs = objOpenSTAAD.Load.GetPrimaryLoadCaseCount()
LoadCombs = objOpenSTAAD.Load.GetLoadCombinationCaseCount()
TotalLoads = PrimaryLCs + LoadCombs
LCNumber.Clear
For varCounter1 = 1 To TotalLoads
LCNumber.AddItem varCounter1
Next
LCNumber.Text = 1
bBadSTAADFile = False
Exit Function
ErrorHandler:
bBadSTAADFile = True
MsgBox "STAAD File does not exist or proper analysis results cannot be found. Please check the STAAD file."
End Function
Private Sub NodeNumber_Change()
End Sub
Private Sub STAADFileName_Change()
End Sub
Private Sub UpdateSTDFile_Click()
bBadSTAADFile = True
FillBoxesWithData
End Sub