I'm working on a macro which consists of a userform which does the following:
- allows a user to browse and select a target XLSX file
- opens the file a displays all worksheet names (not codenames) within a listbox
- copies a cell range on the selected worksheet to a 2D array
So far I have been successful and can access the data in the array however I have hit a stumbling block. This is the first time I've used IPrimitiveCommandEvents and the remaining steps I am trying to achieve are:
- Place a data point at the bottom left of a table.
- The data point origin coordinates are stored in another point3d for reuse when the next array column data needs to be created on a new row in the table
- The first column in the array will be used to create individual text elements starting at an offset X & Y position from the data point and after the first text element is placed, each other placed 5 metres to the right of the previous.
- Once the first array column has looped through to the end, we move to the next array column and repeat above using the additional point3d mentioned in 2. to reset back to the original data point and use a different X & Y offset to that used in 3.
Currently I can place a single piece of text but its location appears to be offset and placed at the end of the loop (i.e. number of rows in array multiplied by spacing between text elements) instead of placing one element, move position, place the next element from the array. Here is some of the code relevant to the operation:
Private Sub IPrimitiveCommandEvents_DataPoint(Point As Point3d, ByVal View As View) Dim oText As Element Set oText = TextFromArray(Point) oText.Redraw msdDrawingModeNormal ActiveModelReference.AddElement oText End Sub Private Function TextFromArray(Point As Point3d) As Element Dim C As Long Dim i As Integer Dim el As Element Dim DataPoint As Point3d Dim R As Long Dim sHorizOffset As Point3d DataPoint = Point 'remember the original data point coordinates i = 1 sHorizOffset = Point3dFromXYZ(5, 0, 0) Point = Point3dAdd(Point, Point3dFromXYZ(13.5, 52.25, 0)) 'set the offset from the data point for the chainage column For i = 1 To lNumRows Debug.Print "i=" & i Set el = CreateTextElement1(Nothing, CStr(ArrayData(1, i)), Point, Matrix3dIdentity) Set TextFromArray = el 'i = i + 1 Point = Point3dAdd(Point, sHorizOffset) Next i End Function
It's not finished as I've yet to add lines to deal with the other columns in the array, I'm simply trying to achieve the creation of individual text elements from the 1st column in the array.
Any suggestions welcome