[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
  • I suspect that the circle used to define your fence is being stroked to a different number of points based on it's size in the view.

    Fence processing works on a set of convex clip planes, so when a fence is defined by curves and the fence has a view associated with it, it's stroked to a view based tolerance. Lots of clip planes means testing against the fence takes more time.

    If you want to use a fence for this, try creating it from a N-sided polygon (choose a reasonable number for N that doesn't take to long to process and is accurate enough for your use case). The approach Jan outlines is perfectly reasonable as well.

    HTH

    -B



  • I did the test and turned the circle into a polygon, the problem persisted

    code that creates a fence from a polygon

    Sub FencePolygon(origin As Point3d, radius As Double)
    
    
    Dim nVertices As Long
    nVertices = 1000
    Dim vertices() As Point3d
    ReDim vertices(0 To nVertices - 1)
    Dim n As Long
    Dim angle As Double
    For n = 0 To nVertices - 1
      angle = 2 * Pi * n / nVertices
      vertices(n).X = origin.X + radius * Cos(angle)
      vertices(n).Y = origin.Y + radius * Sin(angle)
      vertices(n).Z = 0#
    Next n
    
    Const View1 As Long = 1
    Dim oFence As Fence
    Set oFence = ActiveDesignFile.Fence
    oFence.DefineFromModelPoints View1, vertices
    
    End Sub

    I wrote a demo as if someone wanted to test. I do not understand the solution by Jan. :_(

    demo zoom problem.dgndemo.mvba

  • code that creates a fence from a polygon

    I do not know how a circle is "polygonized", but to use 1000 vertices sounds like an overkill to me.

    Did you try something like 50 or 100 to measure whether there is any difference?

    I do not understand the solution by Jan

    What exactly you do not understand?

    Scanning element is basic MicroStation VBA operation, documented well by many examples both in MicroStation VBA help and I guess also in mvba files delivered with MicroStation.

    To use ElementScanCriteria with IncludeOnlyWithinRange is probably not demonstrated on exampe, but it's not different from other types of scanning, plus it's possible to find older discussions about this method.

    Or is the problem in the second step?

    With regards,

      Jan

Reply Children
No Data