我正在尝试制作一个领导者,它根据用户输入从某个点开始,然后第二个点将在x&y中距离50个单位。我认为这个概念应该有效,但我在将 50 添加到数组值时遇到了问题。这就是我所拥有的,我得到了一个类型不匹配:
Set annotationObject = Nothing
Dim StartPoint As Variant
leaderType = acLineWithArrow
Dim Count As Integer
Dim points(0 To 5) As Double
StartPoint = ACAD.ActiveDocument.Utility.GetPoint(, "Specify insertion point")
MsgBox StartPoint(0) & "," & StartPoint(1) & "," & StartPoint(2)
StartPoint(3) = StartPoint(0) + 50
StartPoint(4) = StartPoint(1) + 50
StartPoint(5) = StartPoint(2)
Set leader1 = ACAD.ActiveDocument.ModelSpace.AddLeader(StartPoint, annotationObject, leaderType)
下面的行将一个包含 3 个元素的数组分配给变量 StartPoint,这是一个变体。
StartPoint = ACAD.ActiveDocument.Utility.GetPoint(, "Specify insertion point")
然后,下面的行尝试将另一个元素添加到变体 StartPoint。
StartPoint(3) = StartPoint(0) + 50
但是由于 StartPoint 已经收到一个具有 3 个元素的单个维度的数组,因此其内部表示形式已经设置好。"变体变量维护它们存储的值的内部表示形式( - 来自微软(。
试试这个:
Dim StartPoint As Variant
Dim LeaderPt(8) As Double 'a separate array for leader points
'Specify insertion point
StartPoint = ACAD.ActiveDocument.Utility.GetPoint(, "Specify insertion point")
'-----Set points for the leader-----
LeaderPt(0) = StartPoint(0)
LeaderPt(1) = StartPoint(1)
LeaderPt(2) = StartPoint(2)
LeaderPt(3) = StartPoint(0) + 50 '2nd point x coordinate.
LeaderPt(4) = StartPoint(1) + 50 '2nd point y coordinate.
LeaderPt(5) = StartPoint(2)
'add a third point so the last point of the leader won't be set to (0,0,0)
LeaderPt(6) = LeaderPt(3) + 25 '3rd point x coordinate. Offset from second point
LeaderPt(7) = LeaderPt(4) '3rd point y coordinate. Same as the second point
LeaderPt(8) = LeaderPt(5)
'---
Set leader1 = ACAD.ActiveDocument.ModelSpace.AddLeader(LeaderPt, annotationObject, leaderType)