馨馨 发表于 2016-4-27 21:36:48

VBA做规则格网

已经读取txt文本中的坐标值,比较了X和Y的最大最小值,设置了每个网格的尺寸,但是没有画出格网来,不知道哪里出错了,求各位大神指导Dim L As Integer
Dim H(10000) As Double, X(10000) As Double, Y(10000) As Double, Z(10000) As Double
Dim Xmax As Double, Xmin As Double, Ymax As Double, Ymin As Double
Sub txt_read()
Dim txtname As String
Dim L As Integer

'读取文件
    L = 0 '初始值
    Open "E:\demdata.txt" For Input As #1'打开文件
    Xmax = 0: Xmin = 0
    Ymax = 0: Ymin = 0
    Do While Not EOF(1) '文件读取循环
    If X(L) >= Xmax Then
    Xmax = X(L)
    End If
    If Y(L) >= Ymax Then
    Ymax = Y(L)
    End If
    If X(L) <= Xmin Then
    Xmin = X(L)
    End If
    If Y(L) <= Ymin Then
    Ymin = Y(L)
    End If
    L = L + 1 '个数加1
    Input #1, H(L), X(L), Y(L), Z(L) '读取文件数据, H贮存点序号,XYZ为坐标
    Loop '文件读取循环
    Close #1 '关闭文件
   
'绘制格网
Dim plineObj As AcadLWPolyline
Dim points(0 To 11) As Double
Dim M As Integer'行数
Dim N As Integer'列数
Dim Dx As Double'每个网格x值
Dim Dy As Double'每个网格y值
' 定义多段线的点
    Dx = 14.5
    Dy = 15.6
    M = (Xmax - Xmin) / Dx '求出行数
    N = (Ymax - Ymin) / Dy '求出列数
    points(0) = Xmin: points(1) = Ymin: points(2) = 0
    points(3) = Xmin: points(4) = Ymax: points(5) = 0
    points(6) = Xmax: points(7) = Ymax: points(8) = 0
    points(9) = Xmax: points(10) = Ymin: points(11) = 0
    '在模型空间中创建一个多段线对象
    Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
    ZoomAll
End Sub
页: [1]
查看完整版本: VBA做规则格网