微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用vba在多个点之间绘制多段线

如何解决如何使用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

解决方法

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

互联网上有很多examples

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 处开始坐标数组。

这有帮助吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。