代码改变世界

VB编程在AutoCAD绘图空间创建直线

2011-06-12 14:41  精诚所至 金石为开  阅读(714)  评论(0编辑  收藏  举报

给出直线的起点和终点的三维坐标,利用AddLine方法可以创建直线。如下代码创建一条(1,1,0)与(15,15,0)之间的直线。

Private Sub Command1_Click()
    Dim lineobj As AcadLine
    Dim startpoint(0 To 2) As Double
    Dim endpoint(0 To 2) As Double
    startpoint(0) = 1#: startpoint(1) = 1#: startpoint(2) = 0#
    endpoint(0) = 15#: endpoint(1) = 15#: endpoint(2) = 0#
    Set lineobj = acadapp.ActiveDocument.ModelSpace.AddLine(startpoint, endpoint)
    ZoomAll
End Sub

利用AddLightWeightPolyline方法可以创建轻便多义线,该方法需要多义线的各个定点坐标,如下代码创建一条以(1,1)、(3,2)、(4,9)为定点的多义线。

Private Sub Command1_Click()
    Dim plineobj As AcadLWPolyline
    Dim points(0 To 5) As Double
    points(0) = 1: points(1) = 1
    points(2) = 3: points(3) = 2
    points(4) = 4: points(5) = 9
    Set plineobj = acadapp.ActiveDocument.ModelSpace.AddLightWeightPolyline(points)
    ZoomAll
End Sub

利用AddPolyline方法可以创建普通多义线,该方法需要给出多义线各个顶点的三维坐标点。