- 积分
- 0
- 注册时间
- 2004-5-13
- 仿真币
-
- 最后登录
- 1970-1-1
|
在VB中调用Flac3d.exe的源代码:
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
本文参考了zbocyq在<Re:请问如何在VB中使用FLAC 3D>中的部分代码,在此表示感谢!
感谢西南交大土木工程学院robby同学无私提供命令流!! |
评分
-
1
查看全部评分
-
|