指定三维坐标

AutoCAD ActiveX/VBA

 
指定三维坐标
 
 
 

输入三维世界坐标系 (WCS) 坐标与输入二维 WCS 坐标类似。只是除了指定 XY 值以外,还要指定 Z 值。就像用于二维坐标一样,变量用于向 ActiveX® 方法和特性传递坐标,也用于查询坐标。

有关指定三维坐标的详细信息,请参见《用户手册》中的“输入三维坐标”。

定义和查询二维和三维多段线的坐标

本样例创建两条多段线,每条都有三个坐标。第一条是二维多段线,第二条是三维多段线。请注意,创建三维多段线时,包含顶点的数组的长度会拉伸以包含 Z 坐标。然后,样例查询多段线的坐标,并将坐标显示在消息框中。

Sub Ch8_Polyline_2D_3D()
    Dim pline2DObj As AcadLWPolyline
    Dim pline3DObj As AcadPolyline
      
    Dim points2D(0 To 5) As Double
    Dim points3D(0 To 8) As Double
      
    ' 定义三个二维多段线点
   points2D(0) = 1: points2D(1) = 1
   points2D(2) = 1: points2D(3) = 2
   points2D(4) = 2: points2D(5) = 2
      
    ' 定义三个三维多段线点
   points3D(0) = 1: points3D(1) = 1: points3D(2) = 0
   points3D(3) = 2: points3D(4) = 1: points3D(5) = 0
   points3D(6) = 2: points3D(7) = 2: points3D(8) = 0
      
    ' 创建二维优化多段线
    Set pline2DObj = ThisDrawing.ModelSpace. _
                             AddLightWeightPolyline(points2D)
    pline2DObj.Color = acRed
    pline2DObj.Update
      
    ' 创建三维多段线
    Set pline3DObj = ThisDrawing.ModelSpace. _
                             AddPolyline(points3D)
    pline3DObj.Color = acBlue
    pline3DObj.Update
      
    ' 查询多段线的坐标
    Dim get2Dpts As Variant
    Dim get3Dpts As Variant
      
    get2Dpts = pline2DObj.Coordinates
    get3Dpts = pline3DObj.Coordinates
      
    ' 显示坐标
      
    MsgBox ("2D polyline (red): " & vbCrLf & _
            get2Dpts(0) & ", " & get2Dpts(1) & vbCrLf & _
            get2Dpts(2) & ", " & get2Dpts(3) & vbCrLf & _
            get2Dpts(4) & ", " & get2Dpts(5))
      
    MsgBox ("3D polyline (blue): " & vbCrLf & _
            get3Dpts(0) & ", " & get3Dpts(1) & ", " & _
            get3Dpts(2) & vbCrLf & _
            get3Dpts(3) & ", " & get3Dpts(4) & ", " & _
            get3Dpts(5) & vbCrLf & _
            get3Dpts(6) & ", " & get3Dpts(7) & ", " & _
            get3Dpts(8))
End Sub