Moe Nay
Moe Nay

Reputation: 99

Adding value to individual array values

I am trying to make a leader which starts at a point as per users input and then the second point will be 50 units away in the x & y. I think the concept should work but what i am having problems with adding the 50 to the array values. This is what i have and i'm getting a type mismatch :

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)

Upvotes: 0

Views: 71

Answers (1)

Floben Dale Moro
Floben Dale Moro

Reputation: 93

The line below assigns an array with 3 elements to the variable StartPoint, which is a variant.

StartPoint = ACAD.ActiveDocument.Utility.GetPoint(, "Specify insertion point")

then, the line below tried to add another element to the variant StartPoint.

StartPoint(3) = StartPoint(0) + 50

But since StartPoint already received an array with a single dimension with 3 elements, its internal representation is already set. "Variant variables maintain an internal representation of the values that they store ( - from microsoft)."

Try this:

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)

Upvotes: 1

Related Questions