【问题标题】:How to plot a polyline between multiple points with vba如何使用vba在多个点之间绘制折线
【发布时间】:2021-07-06 17:40:40
【问题描述】:

我正在尝试将 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

【问题讨论】:

  • 请阅读最小、完整和可验证的示例:stackoverflow.com/help/mcve
  • 轻量级折线接受二维顶点列表。
  • 此外,坐标数组可能是基于零的索引。但是您的代码不完整。你甚至没有向我们展示你是如何声明你的 points 数组变量的。

标签: vba autocad polyline


【解决方案1】:

您的代码不完整,但我注意到您的坐标列表从索引 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 开始坐标数组。

这有帮助吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-20
    • 1970-01-01
    • 2018-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多