关于读取文本的紧急求助!
我现在急需要将文本格式(比如hac.txt)的数据根据X,Y坐标和半径Radius调到CAD里面画圆,请各位帮帮忙! 以下是数据的格式.其中"MaximumHeight"是没有用的.X Y MaximumHeight Radius
-38 0 11110 0.0474054054054
-38 0.44 11110 0.0474054054054
-37.6189488223 0.22 11110 0.0476319763759
-38.3810511777 0.22 11110 0.0471788344349
-37.6189488223 -0.22 11110 0.0476319763759
-38.3810511777 -0.22 11110 0.0471788344349
-38 -0.44 11110 0.0474054054054
-38 0.88 11110 0.0474054054054
-37.56 0.76210235533 11110 0.047667027027
-38.44 0.76210235533 11110 0.0471437837838
-37.2378976447 0.44 11110 0.0478585473464
-38.7621023553 0.44 11110 0.0469522634644
-37.12 1.03087894124e-015 11110 0.0479286486486
-38.88 1.03087894124e-015 11110 0.0468821621622
-37.2378976447 -0.44 11110 0.0478585473464
-38.7621023553 -0.44 11110 0.0469522634644
-37.56 -0.76210235533 11110 0.047667027027
-38.44 -0.76210235533 11110 0.0471437837838
-38 -0.88 11110 0.0474054054054
-38 1.32 11110 0.0474054054054
Sub ReadTextDrawCircle()
'数据文件位置
Dim File As String
File = "d:/program/vba/data.txt"
Dim txtLine As String
Dim Center(2) As Double
Dim Radius As Double
Open File For Input As #1
Line Input #1, txtLine ' 读第一行标题行。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, txtLine ' 读入一行数据并将其赋予某变量。
Center(0) = Val(Left(txtLine, 20)) '圆心的X坐标
Center(1) = Val(Mid(txtLine, 21, 20)) '圆心的Y坐标
Radius = Val(Right(txtLine, 20)) '半径
ThisDrawing.ModelSpace.AddCircle Center, Radius '画圆
Loop
Close #1
ZoomExtents '缩放到全图
End Sub 实在太谢谢老大了!终于搞定了!再谢谢! File = "d:/program/vba/data.txt"
这一句可不可以改成由用户打开并寻找txt文件呢? 可以啊,在实用函数栏目中找吧。 CommonDialog1.Filter = "文本文件 (*.txt)|*.txt|"
CommonDialog1.DialogTitle = "打开文件"
CommonDialog1.FilterIndex = 2
CommonDialog1.ShowOpen
File = CommonDialog1.FileName
在此感谢二楼的先生,帮我解决CAD与*.TXT连通问题。
------------------------------------------------------------------------
CQY 如果再把修改过的CAD文件(全是圆点)怎么导出到txt中呢? 我改了一点,可出现了错误了,怎么办?
Sub ReadTextDrawCircle()
'数据文件位置
Dim File As String
CommonDialog1.Filter = "TXT文件|*.txt|DAT文件|*.dat"
CommonDialog1.DialogTitle = "打开文件"
CommonDialog1.ShowOpen
File = CommonDialog1.FileName
Dim txtLine As String
Dim Center(2) As Double
Dim Radius As Double
Open File For Input As #1
Line Input #1, txtLine ' 读第一行标题行。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, txtLine ' 读入一行数据并将其赋予某变量。
Center(0) = Val(Left(txtLine, 20)) '圆心的X坐标
Center(1) = Val(Mid(txtLine, 21, 20)) '圆心的Y坐标
Radius = Val(Right(txtLine, 20)) '半径
ThisDrawing.ModelSpace.AddCircle Center, Radius '画圆
Loop
Close #1
ZoomExtents '缩放到全图
End Sub
在窗体中插入CommonDialog控件,添加CommandButton控件:
Private Sub CommandButton1_Click()
On Error Resume Next
Dim File As String
CommonDialog1.Filter = "TXT文件|*.txt|DAT文件|*.dat"
CommonDialog1.DialogTitle = "打开文件"
CommonDialog1.ShowOpen
File = CommonDialog1.FileName
If File = "" Then Exit Sub
Dim txtLine As String
Dim Center(2) As Double
Dim Radius As Double
Open File For Input As #1
Line Input #1, txtLine ' 读第一行标题行。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, txtLine ' 读入一行数据并将其赋予某变量。
Center(0) = Val(Left(txtLine, 20)) '圆心的X坐标
Center(1) = Val(Mid(txtLine, 21, 20)) '圆心的Y坐标
Radius = Val(Right(txtLine, 20)) '半径
ThisDrawing.ModelSpace.AddCircle Center, Radius '画圆
Loop
Close #1
ZoomExtents '缩放到全图
End Sub
页:
[1]