Excel Range to Array to Addline array

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Addline takes two three-element array of doubles. my data i want to use is in a 3 wide column in excel. its very easy to put into an array.
Dim arpt As Variant
arpt = Range("B17:D28")
this is just my prototype, I am trying to work out a general method to use with different products. what i really want is dynamic naming of variables. googling that, i dont think its available in VBA and everyone says to use arrays.
the range above has 12 lines, i have hard coded these to show (myself) it works, but i am trying to avoid writing 12 or later many more
dim pt1 (0 to 2) as double
which is the normal input for addline.
i cannot just put the addline in a loop as i am running down the excel list. the points do not all connect. sometimes i want to draw a circle at a location. that code has to be written for the application.
the ideal would be to dynamically create variable names such as
for i = 1 to 50
dim (strcat "pt" & ctos(i)) (0 to 2) as double
next i
creating suitable pt1, pt2 etc and then assign values from the array in a similar way.
i could get the variable names from the spreadsheet cell if that would work.
has anybody solved this problem? it seems like a general holdup to drawing from excel. i can rather easily in excel make lists of points that represent corners to draw to, centers of circles, etc.
this below does work but its a bit tedious also.
Dim i As Integer
Dim lineobj As AcadLine
Dim arpt As Variant
arpt = Range("B17:D28")
Dim pt1(1 To 3) As Double
Dim pt2(1 To 3) As Double
For i = 1 To 3
pt1(i) = arpt(1, i)
pt2(i) = arpt(2, i)
Next
Set lineobj = ACAD.ActiveDocument.ModelSpace.AddLine(pt1, pt2)
edit: the range is B17 to D28, the format is misinterpreting by colon as smiley face. not happy. 😉