Quantcast
Channel: MicroStation Programming Forum - Recent Threads
Viewing all articles
Browse latest Browse all 7260

[V8i VBA] Creating multiple text elements from 2D array

$
0
0

I'm working on a macro which consists of a userform which does the following:

  1. allows a user to browse and select a target XLSX file
  2. opens the file a displays all worksheet names (not codenames) within a listbox
  3. 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:

  1. Place a data point at the bottom left of a table.
  2. 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
  3. 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.
  4. 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


Viewing all articles
Browse latest Browse all 7260

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>