首页 > 解决方案 > 如何使用vba在多个点之间绘制折线

问题描述

我正在尝试将 vba 中多个点之间的折线绘制到 AutoCAD 中。我几乎完成了我的代码,但问题是这些点可能会重复,因为 2 行可以有相同的起点,而这些点也不是排序的。我需要能够添加所有点,即使它们没有排序,因为我必须保持我试图绘制的点的顺序。我收到此错误:

Invalid Procedure or argument call
Set acadPol = acadDoc.ModelSpace.AddLightWeightPolyline(Points)

这是我的代码:

Points(1)=9736.242889: Points(2)=9954.553808
Points(3)=9718.429708: Points(4)=9936.874562


If acadDoc.ActiveSpace = acModelSpace Then
Set acadPol = acadDoc.ModelSpace.AddLightWeightPolyline(Points)
Else
Set acadPol = acadDoc.PaperSpace.AddLightWeightPolyline(Points)
End If
acadPol.Closed = False
acadPol.Update
End If
        End If

标签: vbaautocadpolyline

解决方案


您的代码不完整,但我注意到您已从索引 1 开始您的坐标列表。

网上有很多例子

Sub Example_AddLightWeightPolyline()
    ' This example creates a lightweight polyline in model space.

    Dim plineObj As AcadLWPolyline
    Dim points(0 To 9) As Double

    ' Define the 2D polyline points
    points(0) = 1: points(1) = 1
    points(2) = 1: points(3) = 2
    points(4) = 2: points(5) = 2
    points(6) = 3: points(7) = 2
    points(8) = 4: points(9) = 4
    
    ' Create a lightweight Polyline object in model space
    Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)
    ZoomAll

End Sub

如您所见,您需要从索引 0 而不是 1 开始坐标数组。

这有帮助吗?


推荐阅读