标题: 基于VB的SW二次开发,从txt中输入点 [打印本页] 作者: pinkfly 时间: 2008-4-6 14:14 标题: 基于VB的SW二次开发,从txt中输入点 我要从txt中读取点云数据的三维坐标值,并输入到SolidWorks中绘成点,
其中txt格式为多行,每行三个数字值,分别表示x,y和z坐标;
比如text3的内容如下(共12行):
33.4391 -13.80677 -18.66343
33.1812 -13.80677 -18.89947
32.71694 -13.80677 -19.27025
32.47022 -13.80677 -19.45361
32.22339 -13.80677 -19.63
31.97611 -13.80677 -19.78291
31.72859 -13.80677 -19.9218
31.48109 -13.80677 -20.06222
31.23331 -13.80677 -20.18699
30.98543 -13.80677 -20.30678
30.73736 -13.80677 -20.41619
30.48906 -13.80677 -20.51301作者: pinkfly 时间: 2008-4-6 14:19
我vb的编程是这样的:
Dim swApp As Object
Dim filename As Variant
Dim Part As Object
Sub main()
Dim textline As Variant
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Dim x As Double
Dim y As Double
Dim z As Double
'读取txt数据,并进入绘图模式
Open "F:\study\sw-ercikaifa\test\test3.txt" For Input As #1
Part.InsertSketch2 True
'逐行得出字符串格式,分割行数据,拆分成三个数字
Do While Not EOF(1)
Line Input #1, textline
Dim point As Variant
point = Split(textline, " ")
x = Val(point(0)) / 1000
y = Val(point(1)) / 1000
z = Val(point(2)) / 1000
Part.CreatePoint2 x, y, z
Part.ClearSelection2 True
Part.SetPickMode
Loop
Close #1
End Sub