Private Sub Command1_Click()
'定義打開Flac時返回的值
Dim Flac As Long
'在VB中調用Flac3d
Flac = Shell("E:\工具箱\FLAC 3D\flac3d v3.00-251\Flac3d v3.00\f3d300.exe", vbNormalFocus)
' 激活Flac,使其窗口獲得焦點
'AppActivate Flac
'使用代碼模擬鍵盤輸入
' 按下回車鍵給計算器
SendKeys "{Enter}", True
'SendKeys "gen zone brick", True
'SendKeys "{Enter}", True
'SendKeys "plot surface", True
'SendKeys "{Enter}", True
'SendKeys "{Enter}", True
'調用命令流
SendKeys "call F:\VB\work\test.dat", True
SendKeys "{Enter}", True
End Sub
test.dat:
restore tcav3.sav
call stable.dat
stable.dat:
;;顯示支撐軸力得變化
plot hist 7
;;excavate the fourth layer
model null ran group pcav4
;;支撐穩定性判斷程序
;讀出數據,將其輸到文件c:\panda\t1.txt中
;;read the force from flac
def stable
loop t(1,200) ;每500步判斷壹次
;;計算200步
command
step 200
endcommand
command
;;刪除舊有文件
Sys del F:\VB\work\t1.txt
;;打開文件開關,並將支撐軸力錄入到c:\panda\t1.txt中。
set log on
set logfile F:\VB\work\t1.txt
print sel beam force
set log off
;;調用vb程序
Sys start /wait F:\VB\work\inputdata.exe
endcommand
;;讀入數據之前的定義
a_size = 1
IO_READ = 0
IO_WRITE = 1
IO_FISH = 0
IO_ASCII =1 ;當需要讀入,需使用ASCII模式
filename = 'output.txt' ; 註意:如果要進行文件操作,必須先定義,不能直接使用。
;;讀入數據
;;define the array
array var(1)
;;3.輸入數據
status=open(filename,IO_READ,IO_ASCII)
status=read(var,a_size)
status=close
;;將在z_d初始化為零
z_d=0
;;對數據類型進行轉化
z_d=int(var(1))
;;判斷是否失穩,如果輸入數據為0,則繼續循環,如果輸入數據為1,則判斷失穩並跳出循環將所有桿剛度設為0
if z_d=1 then
command
;;將所有桿設置剛度設為很小
sel beam id=1 prop density 1.9 emod=1.0e8 nu=0.0003 &
xcarea=0.00968 xciy=0.844e-3 xciz=0.844e-3 xcj=0
endcommand
exit
endif
endloop
end
stable
solve
save pcav4.sav
inputdata.exe的源代碼:
'工程文件路徑
Public strInputPath As String
Public strOutputPath As String
Private Sub Form_Load()
'隱藏窗口
Me.Hide
'定義極限荷載
Dim Plim As Single
'定義桿件失穩標記
'如果桿件失穩則輸出1,如果沒有失穩則輸出0
Dim nFlag As Integer
Plim = 10.44 * 100000# '根據0.85的折減系數而得
'定義單元編號
Dim nEleID As Integer
'定義節點編號
Dim nNodeID As Integer
'定義桿件節點的軸力的分量
Dim F(1 To 3) As Single
'定義字符串變量
Dim str As String
'定義讀入數據前忽略的行數
Dim nLine As Integer
nLine = 21
'定義欲讀入單元的個數
Dim nElement As Integer
nElement = 10
'定義每個單元的節點數
Dim nNode As Integer
nNode = 2
'定義可供Open語句使用的文件號
Dim nInputFile As Integer
Dim nOutputFile As Integer
'FreeFile函數返回壹個Integer,代表下壹個可供Open語句使用的文件號
nInputFile = FreeFile
nOutputFile = nInputFile + 1
'打開文本文件
strInputPath = "F:\VB\work\t1.txt"
strOutputPath = "F:\VB\work\output.txt"
Open strInputPath For Input As #nInputFile
Open strOutputPath For Output As #nOutputFile
'讀入忽略的行數
For i = 1 To nLine
Line Input #nInputFile, str
Next i
'讀入數據
'For i = 1 To nElement
For i = 1 To 1
For j = 1 To nNode
'If j = 1 Then
' Input #nInputFile, nEleID, nNodeID, F(1), F(2), F(3)
'Else
' Input #nInputFile, nNodeID, F(1), F(2), F(3)
'End If
If j = 1 Then
Input #nInputFile, nEleID
End If
Input #nInputFile, nNodeID, F(1), F(2), F(3)
'將軸力值與桿件的極限載荷相對比,如果桿件失穩則輸出1,如果沒有失穩則輸出0
If j = 1 Then
If Plim < (-F(1) * 3) Then
nFlag = 1
Else
nFlag = 0
End If
Write #nOutputFile, nFlag
End If
Next j
Next i
'關閉文件
Close #nInputFile
Close #nOutputFile
'卸載窗體
Unload Me
End Sub