创建多面网格

AutoCAD ActiveX/VBA

 
创建多面网格
 
 
 

使用 AddPolyfaceMesh 方法可以创建多面网格,其中每个面都可以有很多顶点。

创建多面网格与创建矩形网格类似。要创建多面网格,首先为其顶点指定坐标,然后通过输入面的所有顶点的顶点编号来定义该面。创建多面网格时,可以将特定边设置为不可见、指定边所在的图层或边的颜色。

要使某个边不可见,可以为该边的顶点编号输入负值。关于创建多面网格的详细信息,请参见《ActiveX and VBA Reference》中介绍的 AddPolyfaceMesh 方法。

创建多面网格

本样例在模型空间中创建一个多面网格对象。然后更新活动视口的观察方向,以便于查看网格的三维情况。

Sub Ch8_CreatePolyfaceMesh()
    ' 定义网格顶点
    Dim vertex(0 To 17) As Double
    vertex(0) = 4: vertex(1) = 7: vertex(2) = 0
    vertex(3) = 5: vertex(4) = 7: vertex(5) = 0
    vertex(6) = 6: vertex(7) = 7: vertex(8) = 0
    vertex(9) = 4: vertex(10) = 6: vertex(11) = 0
    vertex(12) = 5: vertex(13) = 6: vertex(14) = 0
    vertex(15) = 6: vertex(16) = 6: vertex(17) = 1
      
    ' 定义面列表
    Dim FaceList(0 To 7) As Integer
    FaceList(0) = 1
    FaceList(1) = 2
    FaceList(2) = 5
    FaceList(3) = 4
    FaceList(4) = 2
    FaceList(5) = 3
    FaceList(6) = 6
    FaceList(7) = 5
    ' 创建多面网格
    Dim polyfaceMeshObj As AcadPolyfaceMesh
    Set polyfaceMeshObj = ThisDrawing.ModelSpace.AddPolyfaceMesh _
                                  (vertex, FaceList)
      
    ' 更改视口的观察方向
    ' 以便于查看多面网格
    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