[MicroStation V8i SS3 VBA] Why the macro execution speed depends on the zoom in the drawing?

Hello, whenever I have a macro with a loop that scans the fence, when the zoom in the drawing is large, the program works slowly and when the zoom is small, the program works quickly?

same task:

time for big zoom

time for small zoom

Parents Reply Children
  • the program gets the vertices from polyline, then the loop sets a fence at each vertex with the code:

    Sub setFence(vetex As Point3d, radius As Double)
    Dim rotation As Matrix3d
    Dim oText As TextElement
    Dim oCircle As EllipseElement
    
    rotation = Matrix3dFromAxisAndRotationAngle(2, 0)
    Set oCircle = CreateEllipseElement2(Nothing, vetex, radius, radius, rotation)
    
    With ActiveSettings
      .FenceVoid = False
      .FenceClip = False
      .FenceOverlap = True
    End With
    
    Set oView1 = ActiveDesignFile.Views(1)
    Set oFence = ActiveDesignFile.Fence
    oFence.DefineFromElement oView1, oCircle
    End Sub

    then it scans the texts from the fence according to the scheme

    :

    Sub ScanFence()
    Dim counter As Integer
    Dim oElement As Element
    Dim oEnumerator As ElementEnumerator
    Dim oFence As Fence
    Set oFence = ActiveDesignFile.Fence
    If oFence.IsDefined = True Then
    Set oEnumerator = oFence.GetContents
    Do While oEnumerator.MoveNext
    Set oElement = oEnumerator.Current
    If oElement.Color = 5 Then
    If oElement.Type = msdElementTypeLine Or oElement.Type = msdElementTypeText Then
    counter = counter + 1
    End If
    End If
    Loop
    MsgBox "The total number of elements scanned for are: " & CStr(counter)
    Else
    ShowError "A Fence Has Not Been Defined!"
    End If
    End Sub

    next program calculate ... and the loop moves to the next vertex ...

  • Hi Mateusz,

    in my opinion the code is fine.

    And what about runtime conditions (fence size vs view...) I asked for?  It's the only difference between the discussed cases I see now.

    I can imagine (but it should be confirmed by Bentley and also tested using some simple test macro) that when the fence is "inside view", it's optimized, because the view processing is optimized as much as possible, whereas when it's "outside view", the processing is slower.

    A question is: Has fence to be used? Isn't e.g. scanning using e.g. range enough? To test (real) elements overlap is always slower than (simple) range comparison.

    With regards,

      Jan

  • Thank you for your response.

    I have another question, how can I otherwise select texts within a radius from a given point without using a fence

  • I have another question, how can I otherwise select texts within a radius from a given point without using a fence

    Following the best practices, it should be posted as a new question, but ... ;-)

    It depends what exactly do you mean by "text within a radius". If it's about the text origin, I would try "two steps search":

    1. Scan using element range, which is very fast, but it does not find "a circle", but "a box".
    2. In the second step, to evaluate exact length between a center and found candidates, which should end with texts "with origins inside the circle"

    Regards,

      Jan