创建网格

AutoCAD ActiveX/VBA

 
创建网格
 
 
 

矩形网格(PolygonMesh 对象)使用平面镶嵌面来表示对象的曲面。网格密度(或镶嵌面的数目)由包含 MN 个顶点的矩阵定义,类似于由行和列组成的栅格。MN 分别指定给定顶点的列和行的位置。在二维和三维空间中都可以创建网格,但它主要用于三维空间。

使用 Add3DMesh 方法可以创建矩形网格。此方法将输入三个值:M 方向的顶点数、N 方向的顶点数和包含网格中所有顶点的坐标的变量数组。

创建 PolygonMesh 之后,可以使用 MClose 和 NClose 特性来结束网格。

有关创建网格的详细信息,请参见《用户手册》中的“创建曲面”。

创建多边形网格

本例创建一个 4×4 多边形网格。然后调整活动视口的方向,以便于查看网格的三维情况。

Sub Ch8_Create3DMesh()
    Dim meshObj As AcadPolygonMesh
    Dim mSize, nSize, Count As Integer
    Dim points(0 To 47) As Double
      
    ' 创建点的矩阵
    points(0) = 0: points(1) = 0: points(2) = 0
    points(3) = 2: points(4) = 0: points(5) = 1
    points(6) = 4: points(7) = 0: points(8) = 0
    points(9) = 6: points(10) = 0: points(11) = 1
    points(12) = 0: points(13) = 2: points(14) = 0
    points(15) = 2: points(16) = 2: points(17) = 1
    points(18) = 4: points(19) = 2: points(20) = 0
    points(21) = 6: points(22) = 2: points(23) = 1
    points(24) = 0: points(25) = 4: points(26) = 0
    points(27) = 2: points(28) = 4: points(29) = 1
    points(30) = 4: points(31) = 4: points(32) = 0
    points(33) = 6: points(34) = 4: points(35) = 0
    points(36) = 0: points(37) = 6: points(38) = 0
    points(39) = 2: points(40) = 6: points(41) = 1
    points(42) = 4: points(43) = 6: points(44) = 0
    points(45) = 6: points(46) = 6: points(47) = 0
      
    mSize = 4: nSize = 4
      
    ' 在模型空间中创建三维网格
    Set meshObj = ThisDrawing.ModelSpace. _
                        Add3DMesh(mSize, nSize, points)
      
    ' 更改视口的观察方向
    ' 以更好地查看圆柱体
    Dim NewDirection(0 To 2) As Double
    NewDirection(0) = -1
    NewDirection(1) = -1
    NewDirection(2) = 1
    ThisDrawing.ActiveViewport.direction = NewDirection
    ThisDrawing.ActiveViewport = ThisDrawing.ActiveViewport
    ZoomAll
End Sub